In [1]:
import cv2
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
filename = '/home/glagasse/Developpement/Projects/Python/Logo/logoconcept.jpg'
img = cv2.imread(filename, 1)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
gray = np.float32(gray)
dst = cv2.cornerHarris(gray,2,3,0.04)
#result is dilated for marking the corners, not important
dst = cv2.dilate(dst,None)
# Threshold for an optimal value, it may vary depending on the image.
img[dst>0.01*dst.max()]=[0,0,255]
In [2]:
def Image_Show(img):
b,g,r = cv2.split(img)
rgb_img = cv2.merge([r,g,b])
plt.imshow(rgb_img)
plt.xticks([]), plt.yticks([])
plt.show()
In [3]:
laplacian = cv2.Laplacian(img,cv2.CV_64F)
sobelx = cv2.Sobel(img,cv2.CV_64F,1,0,ksize=3)
sobely = cv2.Sobel(img,cv2.CV_64F,0,1,ksize=3)
plt.subplot(2,2,1)
plt.imshow(img)
plt.title('Original')
plt.subplot(2,2,2)
plt.imshow(sobelx)
plt.title('SobelX')
plt.subplot(2,2,3)
plt.imshow(sobely)
plt.title('SobelY')
plt.subplot(2,2,4)
plt.imshow(laplacian)
plt.title('Laplacian')
plt.show()
In [4]:
Image_Show(img)
Image_Show(sobelx)
Image_Show(sobely)
Image_Show(laplacian)
In [5]:
hist,bins = np.histogram(img.flatten(),256,[0,256])
cdf = hist.cumsum()
cdf_normalized = cdf * hist.max()/ cdf.max()
plt.plot(cdf_normalized, color = 'b')
plt.hist(img.flatten(),256,[0,256], color = 'r')
plt.xlim([0,256])
plt.legend(('cdf','histogram'), loc = 'upper left')
plt.show()
In [6]:
Hist_R = cv2.calcHist(img, [0], None, [256],[0,256])
Hist_G = cv2.calcHist(img, [1], None, [256],[0,256])
Hist_B = cv2.calcHist(img, [2], None, [256],[0,256])
In [15]:
imgray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(imgray,5,255,0)
image, contours, hierarchy = cv2.findContours(thresh) # ,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
In [14]:
plt.imshow(thresh)
plt.show()
In [ ]: