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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
import os
import sys
from PyQt4 import QtGui
import numpy as np
import matplotlib.pyplot as plt
import PIL # Biblio pour traitement images
from matplotlib import cm
# Traitement images
from skimage.feature import greycomatrix, greycoprops
from skimage import data
# Fichier Excel
from xlwt import Workbook
class Window(QtGui.QMainWindow):
def __init__(self):
super(Window, self).__init__()
self.initUI()
def initUI(self):
"""
self.textEdit = QtGui.QTextEdit()
self.setCentralWidget(self.textEdit)
self.statusBar()
menubar = self.menuBar()
fileMenu = menubar.addMenu('&File')
fileMenu.addAction(openFile)
"""
btn = QtGui.QPushButton("Matrice de cooccurrence", self)
btn.resize(btn.sizeHint())
btn.move(100, 80)
btn.clicked.connect(self.showDialog_coocc)
btn1 = QtGui.QPushButton("Quitter", self)
btn1.setToolTip('Click to quit!')
btn1.clicked.connect(exit)
btn1.resize(btn1.sizeHint())
btn1.move(100, 160)
self.setGeometry(300, 300, 350, 300)
self.setWindowTitle('File dialog')
self.show()
def showDialog_coocc(self):
fname = QtGui.QFileDialog.getOpenFileName(self, 'Open file',
'D:\Documents\THESE\1ereAnnee\Python\Interface_cooc\images')
im = PIL.Image.open(fname)
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)
fig = plt.figure("Cooccurrence")
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')
def main():
app = QtGui.QApplication(sys.argv)
ex = Window()
sys.exit(app.exec_())
if __name__ == '__main__':
main() |
Partager