import cv2 import numpy as np from matplotlib import pyplot as plt img = cv2.imread('couleur.png',0) def Everything (img): laplacian = cv2.Laplacian(img,cv2.CV_64F) sobelx = cv2.Sobel(img,cv2.CV_64F,1,0,ksize=5) sobely = cv2.Sobel(img,cv2.CV_64F,0,1,ksize=5) plt.subplot(2,2,1),plt.imshow(img,cmap = 'gray') plt.title('Original'), plt.xticks([]), plt.yticks([]) plt.subplot(2,2,2),plt.imshow(laplacian,cmap = 'gray') plt.title('Laplacian'), plt.xticks([]), plt.yticks([]) plt.subplot(2,2,3),plt.imshow(sobelx,cmap = 'gray') plt.title('Sobel X'), plt.xticks([]), plt.yticks([]) plt.subplot(2,2,4),plt.imshow(sobely,cmap = 'gray') plt.title('Sobel Y'), plt.xticks([]), plt.yticks([]) plt.show() return laplacian def Laplacian(img): laplacian = cv2.Laplacian(img,cv2.CV_64F) plt.plot,plt.imshow(laplacian,cmap = 'gray') plt.title('Laplacian'), plt.xticks([]), plt.yticks([]) plt.show() return laplacian def SobelX(img): sobelx = cv2.Sobel(img,cv2.CV_64F,1,0,ksize=5) plt.plot,plt.imshow(sobelx,cmap = 'gray') plt.title('Sobel X'), plt.xticks([]), plt.yticks([]) plt.show() return sobelx def SobelY(img): sobely = cv2.Sobel(img,cv2.CV_64F,0,1,ksize=5) plt.plot,plt.imshow(sobely,cmap = 'gray') plt.title('Sobel Y'), plt.xticks([]), plt.yticks([]) plt.show() return sobely def GradientChoiceProcessing(img, choice): if choice == '1': img = Laplacian(img) return img elif choice == '2': img = SobelX(img) return img elif choice == '3': img = SobelY(img) return img elif choice == '4': img = Everything(img) return img else: return def GradientChoice() : image = None print('\t\tGradient Menu\n') while (image is None): image = str(raw_input('\tImage to use? By default couleur.png \n')) if not image: image = 'couleur.png' image = cv2.imread(str(image), 0) print ('\t1. Laplacian\n\t2. Sobel X\n\t3. Sobel Y\n\t4. Everything\n') choice = raw_input('\n\tMultiple choices possible\n') for i in range (0, len(choice)): img = image.copy() img = GradientChoiceProcessing(img, choice[i]) return