# -*- coding: utf-8 -*-
# @Author : Muhammed Furkan GÖKBEL
# @File : Otsu_Yontemle_Esik_Filitreleme.py
# @Software: PyCharm
# Birden fazla threshold işleminde uygulanır
import cv2
import numpy as np
from matplotlib import pyplot as plt


img = cv2.imread('gurultuluresim.JPG',0)
ret,th1 = cv2.threshold(img,127,255,cv2.THRESH_BINARY)
ret,th2 = cv2.threshold(img,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
blur = cv2.GaussianBlur(img,(5,5),0)
ret,th3 = cv2.threshold(blur,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)


########### BLUR VE OTSU YÖNTEM İLE KENAR ALGILAMA
esik1 = 100
esik2 = 150
edge = cv2.Canny(blur,esik1,esik2)

resimler=[img,0,th1,
          img,0,th2,
          blur,0,th3]
basliklar=['orjinal g resim','Histogram','Basit Thresholding(127)',
           'orjinal g resim', 'Histogram','Otsu Thresholding',
            'Gaussian Blur', 'Histogram', 'Otsu Thresholding']

for i in range(3):
    plt.subplot(3,3,i*3+1),plt.imshow(resimler[i*3],'gray')
    plt.title(basliklar[i*3]),plt.xticks([]),plt.yticks([])
    plt.subplot(3,3,i*3+2),plt.hist(resimler[i*3].ravel(),256)
    plt.title(basliklar[i*3+1]),plt.xticks([]),plt.yticks([])
    plt.subplot(3,3,i*3+3),plt.imshow(resimler[i*3+2],'gray')
    plt.title(basliklar[i*3+2]),plt.xticks([]),plt.yticks([])

plt.show()







#cv2.imshow('blur',blur)
#cv2.imshow('img',img)
#cv2.imshow('th1',th1)
#cv2.imshow('th2',th2)
#cv2.imshow('th3',th3)
#cv2.imshow('Otsu&Blur&Canny',edge)
cv2.waitKey(0)
cv2.destroyAllWindows()













