Blame view

Python/Application/Gradient.py 2.22 KB
3f217332   Justine   mise à jour du git
1
  import sys
81de032f   Justine   Ajout de l'applic...
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
  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):
3f217332   Justine   mise à jour du git
64
65
66
67
  		if sys.version_info >= (3, 0):
  			image = str(input('\tImage to use ? By default couleur.png \n'))
  		else:
  			image = str(raw_input('\tImage to use ? By default couleur.png \n'))
81de032f   Justine   Ajout de l'applic...
68
69
70
71
  		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')
3f217332   Justine   mise à jour du git
72
73
74
75
  	if sys.version_info >= (3, 0):
  		choice = input('\n\tMultiple choices possible\n')
  	else:
  		choice = raw_input('\n\tMultiple choices possible\n')
81de032f   Justine   Ajout de l'applic...
76
77
78
79
  	for i in range (0, len(choice)):
  		img = image.copy()
  		img = GradientChoiceProcessing(img, choice[i])
  	return