-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterfaz.py
More file actions
192 lines (173 loc) · 8.23 KB
/
interfaz.py
File metadata and controls
192 lines (173 loc) · 8.23 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/usr/local/bin/python
# This Python file uses the following encoding: utf-8
import os, sys
import tkinter as tk
from tkinter import ttk
import tkinter.filedialog
from matplotlib import pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from PIL import Image
import pydicom
import numpy
import math
import imageFunc
import copy
fileName = "/home/mateo/Documents/Programing/ImageProcessing/prove_images/cameraM.png"
dicomImage = Image.open(fileName)
dicomPixelArray = numpy.array(dicomImage.convert(mode='L').getdata()).reshape(dicomImage.size[0], dicomImage.size[1])
dicomFilteredPixelArray = None
dicomThresholdingPixelArray = None
def searchImage():
global fileName, dicomImage, dicomPixelArray, dicomFilteredPixelArray, dicomThresholdingPixelArray
fileName = tk.filedialog.askopenfilename()
dicomImage = pydicom.dcmread(fileName)
dicomPixelArray = dicomImage.pixel_array
dicomFilteredPixelArray = None
dicomThresholdingPixelArray = None
def showInformation():
imageInfoLabel['text'] = imageFunc.dicomInfo(dicomImage)
def applyFilter():
kernel=selectKernelCBox.get()
size=selectKernelSizeCBox.get()
filter=selectFilterCBox.get()
localDicomPixelArray = dicomPixelArray
global dicomFilteredPixelArray
dicomFilteredPixelArray=copy.copy(imageFunc.applyFilter(kernel, size, filter, localDicomPixelArray))
showFilteredImage()
def thresholding():
global dicomThresholdingPixelArray
global dicomAnglesMatrix
if(dicomFilteredPixelArray is None):
dicomThresholdingPixelArray, dicomAnglesMatrix = copy.copy(imageFunc.sobelFilter(dicomPixelArray))
else:
dicomThresholdingPixelArray,dicomAnglesMatrix=copy.copy(imageFunc.sobelFilter(dicomFilteredPixelArray))
showThresholdImage()
def thresholdingErosion():
global dicomThresholdingErosionPixelArray
struct = selectStruct.get()
print(dicomFilteredPixelArray is None)
if(dicomFilteredPixelArray is None):
dicomThresholdingErosionPixelArray = copy.copy(imageFunc.dilatacionErosion(dicomPixelArray, struct))
else:
dicomThresholdingErosionPixelArray = copy.copy(imageFunc.dilatacionErosion(dicomFilteredPixelArray, struct))
showThresholdErosionImage()
def kmeans():
global dicomKmeansPixelArray
centroids = centroidsText.get("1.0", tk.END)
intCentroids = []
try:
int(centroids.split()[0])
except ValueError:
centroids = "10 20 30"
for i in range (len(centroids.split())):
intCentroids.append(int(centroids.split()[i]))
print(dicomFilteredPixelArray is None)
if(dicomFilteredPixelArray is not None):
dicomKmeansPixelArray = copy.copy(imageFunc.kmeansIntoImage(dicomFilteredPixelArray, intCentroids))
else:
dicomKmeansPixelArray = copy.copy(imageFunc.kmeansIntoImage(dicomPixelArray, intCentroids))
showKmeansImage()
def showImage():
for widget in imageFrame.winfo_children():
widget.destroy()
figure = plt.Figure()
subPlot = figure.add_subplot(111)
subPlot.imshow(dicomPixelArray, cmap=plt.cm.gray)
imagesTemp = FigureCanvasTkAgg(figure, master=imageFrame)
imagesTemp.draw()
imagesTemp.get_tk_widget().pack(padx=5, pady=15)
def showFilteredImage():
for widget in imageFrame.winfo_children():
widget.destroy()
figure = plt.Figure()
subPlot = figure.add_subplot(111)
subPlot.imshow(dicomFilteredPixelArray, cmap=plt.cm.gray)
imagesTemp = FigureCanvasTkAgg(figure, master=imageFrame)
imagesTemp.draw()
imagesTemp.get_tk_widget().pack(padx=5, pady=15)
def showThresholdImage():
for widget in imageFrame.winfo_children():
widget.destroy()
figure = plt.Figure()
subPlot = figure.add_subplot(111)
subPlot.imshow(dicomThresholdingPixelArray, cmap=plt.cm.gray)
imagesTemp = FigureCanvasTkAgg(figure, master=imageFrame)
imagesTemp.draw()
imagesTemp.get_tk_widget().pack(padx=5, pady=15)
def showThresholdErosionImage():
for widget in imageFrame.winfo_children():
widget.destroy()
figure = plt.Figure()
subPlot = figure.add_subplot(111)
subPlot.imshow(dicomThresholdingErosionPixelArray, cmap=plt.cm.gray)
imagesTemp = FigureCanvasTkAgg(figure, master=imageFrame)
imagesTemp.draw()
imagesTemp.get_tk_widget().pack(padx=5, pady=15)
def showKmeansImage():
for widget in imageFrame.winfo_children():
widget.destroy()
figure = plt.Figure()
subPlot = figure.add_subplot(111)
subPlot.imshow(dicomKmeansPixelArray, cmap=plt.cm.get_cmap("Greys"))
imagesTemp = FigureCanvasTkAgg(figure, master=imageFrame)
imagesTemp.draw()
imagesTemp.get_tk_widget().pack(padx=5, pady=15)
filterList=["Sin Filtro","Reduccion","Ignorar","Espejo"]
kernelList=["Promedio","Gaussiano","Rayleigh","Mediano"]
structList=["□","+", "x", "-", "|"]
kernelSize=["3x3","5x5","7x7"]
root = tk.Tk()
root.title("Procesamiento de imagenes")
root.configure(bg="black")
root.geometry("1000x600")
root.resizable(0,0)
imageInfoFrame = tk.Frame(root, bg="black")
imageInfoFrame.pack(side=tk.LEFT, padx= 10, pady=10)
buttonFrame = tk.Frame(root, bg="black")
buttonFrame.pack(side=tk.RIGHT, padx=10, pady=10)
searchImageButton = tk.Button(buttonFrame, text="Search Image", bg="gray30", fg="white", height=1, width=15, command=searchImage)
searchImageButton.pack(padx=5, pady=5)
showImageButton = tk.Button(buttonFrame, text="Show Image", bg="gray30", fg="white", height=1, width=15, command=showImage)
showImageButton.pack(padx=5, pady=5)
showImageInfoButton = tk.Button(buttonFrame, text="Show Image Info", bg="gray30", fg="white", height=1, width=15, command=showInformation)
showImageInfoButton.pack(padx=5, pady=5)
showHistogramButton = tk.Button(buttonFrame, text="Show Histogram", bg="gray30", fg="white", height=1, width=15, command = lambda: imageFunc.ShowHistogram(dicomPixelArray))
showHistogramButton.pack(padx=5, pady=5)
applyFilterButton = tk.Button(buttonFrame, text="Apply Filter", bg="gray30",fg="white", height=1, width=15, command=applyFilter)
applyFilterButton.pack(padx=5, pady=5)
applyBordersButton = tk.Button(buttonFrame, text="Thresholding", bg="gray30",fg="white", height=1, width=15, command=thresholding)
applyBordersButton.pack(padx=5, pady=5)
selectFilterLabel = tk.Label(buttonFrame, text="Seleccione un filtro", bg="black", fg="white")
kmeansButton = tk.Button(buttonFrame, text="K-Means", bg="gray30",fg="white", height=1, width=15, command=kmeans)
kmeansButton.pack(padx=5, pady=5)
ErosionAndDilatataionButton = tk.Button(buttonFrame, text="Erosion y Dilatacion", bg="gray30",fg="white", height=1, width=15, command=thresholdingErosion)
ErosionAndDilatataionButton.pack(padx=5, pady=5)
centroidsLabel = tk.Label(buttonFrame, text="Ingrese los centroides", bg="black", fg="white")
centroidsLabel.pack(padx=5, pady=5)
centroidsText = tk.Text(buttonFrame, height=1, width=15)
centroidsText.pack(padx=5, pady=5)
centroidsText.insert(tk.END, "c1 c2 ... cn")
selectFilterLabel.pack(padx=5, pady=5)
selectFilterCBox = ttk.Combobox(buttonFrame, values=filterList, state="readonly", width=10)
selectFilterCBox.current(0)
selectFilterCBox.pack(padx=5, pady=5)
selectKernelLabel = tk.Label(buttonFrame, text="Seleccione una estructura", bg="black", fg="white")
selectKernelLabel.pack(padx=5, pady=5)
selectStruct = ttk.Combobox(buttonFrame, values=structList, state="readonly", width=3)
selectStruct.current(0)
selectStruct.pack(padx=5, pady=5)
selectKernelLabel = tk.Label(buttonFrame, text="Seleccione un kernel", bg="black", fg="white")
selectKernelLabel.pack(padx=5, pady=5)
selectKernelCBox = ttk.Combobox(buttonFrame, values=kernelList, state="readonly", width=12)
selectKernelCBox.current(0)
selectKernelCBox.pack(side=tk.LEFT, padx=5, pady=5)
selectKernelSizeCBox = ttk.Combobox(buttonFrame, values=kernelSize, state="readonly", width=3)
selectKernelSizeCBox.current(0)
selectKernelSizeCBox.pack(side=tk.RIGHT, padx=5, pady=5)
titleLabel = tk.Label(imageInfoFrame, text="Procesamiento de imagenes", bg="black", fg="white", height=2, width=25, font="Arial 12 bold")
titleLabel.pack(side=tk.TOP, padx=5, pady=5)
imageInfoLabel = tk.Label(imageInfoFrame, text="Aqui se desplegara la informacion "+"\n"+"de la imagen seleccionada", bg="gray", fg="white", height=30, width=35)
imageInfoLabel.pack(padx=5, pady=5)
imageFrame=tk.Frame(root, bg="black")
imageFrame.pack()
root.mainloop()