1 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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
# Interface de dialogue
import Tkinter
import tkFileDialog
# Traitement images
from skimage.feature import greycomatrix, greycoprops
from skimage import data
# Fichier Excel
from xlwt import Workbook
def afficheCanal(c) :
Tkinter.Tk().withdraw() # Close the root window
in_path = tkFileDialog.askopenfilename()
general_path = os.path.split(os.path.abspath(in_path))
im = PIL.Image.open(in_path)
R, G, B = im.split() # R = rouge, G = vert, B = bleu
R = np.asarray(R, dtype = np.uint8)
G = np.asarray(G, dtype = np.uint8)
B = np.asarray(B, dtype = np.uint8)
#R = np.where(R > 25., 255., R)
#R = np.where(R < 5., 0., R)
if c == 1 :
fig = plt.figure("Cooc")
plt.clf() # Purge la figure
ax = fig.add_subplot(2,2,1)
ax.set_title("Image de base")
plt.imshow(R, cmap=cm.gray, origin = "lower")
plt.colorbar()
glcm = greycomatrix(R, [1], [0], 256, symmetric=True, normed=True)
ax = fig.add_subplot(2,2,2)
ax.set_title("Matrice de cooccurrence")
plt.imshow(glcm[:, :, 0, 0], cmap=cm.gray, origin = "lower")
plt.colorbar()
glcm = np.where(glcm > 0., 1., glcm)
ax = fig.add_subplot(2,2,3)
ax.set_title("Matrice de cooccurrence > 0")
plt.imshow(glcm[:, :, 0, 0], cmap=cm.gray, origin = "lower")
plt.colorbar()
contrast = greycoprops(glcm, prop='contrast')
# Create an PyQT4 application object.
a = QtGui.QApplication(sys.argv)
# The QWidget widget is the base class of all user interface objects in PyQt4.
w = QtGui.QWidget()
# Set window size.
w.resize(320, 240)
# Set window title
w.setWindowTitle("Hello World!")
# Add a button
btn = QtGui.QPushButton("Matrice de coocurrence", w)
btn.clicked.connect(lambda : afficheCanal(1))
btn.resize(btn.sizeHint())
btn.move(100, 80)
btn1 = QtGui.QPushButton("Quitter", w)
btn1.setToolTip('Click to quit!')
btn1.clicked.connect(exit)
btn1.resize(btn1.sizeHint())
btn1.move(100, 160)
# Show window
w.show()
sys.exit(a.exec_()) |
Partager