Update app.py
Browse files
app.py
CHANGED
@@ -74,6 +74,11 @@ models = {
|
|
74 |
'UNet3+': torch.jit.load('./model/UNet3plus.pt'),
|
75 |
}
|
76 |
|
|
|
|
|
|
|
|
|
|
|
77 |
def processar_imagem_de_entrada_wrapper(img, modelo):
|
78 |
model = models[modelo]
|
79 |
spent, img_out = processar_imagem_de_entrada(img, modelo, model)
|
@@ -83,9 +88,30 @@ def processar_imagem_de_entrada_wrapper(img, modelo):
|
|
83 |
flattened_img = img_out[:, :, 0].reshape((-1, 1)) # Use the intensity channel
|
84 |
kmeans.fit(flattened_img)
|
85 |
labels = kmeans.labels_
|
86 |
-
|
87 |
-
|
88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
|
90 |
# Formatar o indicador de doença como uma string
|
91 |
if has_disease_flag:
|
@@ -103,6 +129,7 @@ def processar_imagem_de_entrada_wrapper(img, modelo):
|
|
103 |
|
104 |
return spent, img_out, status_doenca, explanation
|
105 |
|
|
|
106 |
# Criar a interface Gradio
|
107 |
my_app = gr.Interface(
|
108 |
fn=processar_imagem_de_entrada_wrapper,
|
|
|
74 |
'UNet3+': torch.jit.load('./model/UNet3plus.pt'),
|
75 |
}
|
76 |
|
77 |
+
from scipy.spatial import distance
|
78 |
+
from scipy.ndimage import label
|
79 |
+
import numpy as np
|
80 |
+
|
81 |
+
|
82 |
def processar_imagem_de_entrada_wrapper(img, modelo):
|
83 |
model = models[modelo]
|
84 |
spent, img_out = processar_imagem_de_entrada(img, modelo, model)
|
|
|
88 |
flattened_img = img_out[:, :, 0].reshape((-1, 1)) # Use the intensity channel
|
89 |
kmeans.fit(flattened_img)
|
90 |
labels = kmeans.labels_
|
91 |
+
cluster_centers = kmeans.cluster_centers_
|
92 |
+
|
93 |
+
# Extração de características dos clusters
|
94 |
+
num_clusters = len(cluster_centers)
|
95 |
+
cluster_features = []
|
96 |
+
for i in range(num_clusters):
|
97 |
+
cluster_pixels = img_out[labels == i]
|
98 |
+
|
99 |
+
# Calcular área do cluster
|
100 |
+
area = len(cluster_pixels)
|
101 |
+
|
102 |
+
# Calcular forma do cluster usando a relação entre área e perímetro
|
103 |
+
_, contours, _ = cv2.findContours(np.uint8(labels == i), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
104 |
+
perimeter = cv2.arcLength(contours[0], True)
|
105 |
+
compactness = 4 * np.pi * area / (perimeter ** 2)
|
106 |
+
|
107 |
+
cluster_features.append({'area': area, 'compactness': compactness})
|
108 |
+
|
109 |
+
# Decidir se há doença com base nas características dos clusters
|
110 |
+
has_disease_flag = False
|
111 |
+
for feature in cluster_features:
|
112 |
+
if feature['area'] >= 200 and feature['compactness'] < 0.3:
|
113 |
+
has_disease_flag = True
|
114 |
+
break
|
115 |
|
116 |
# Formatar o indicador de doença como uma string
|
117 |
if has_disease_flag:
|
|
|
129 |
|
130 |
return spent, img_out, status_doenca, explanation
|
131 |
|
132 |
+
|
133 |
# Criar a interface Gradio
|
134 |
my_app = gr.Interface(
|
135 |
fn=processar_imagem_de_entrada_wrapper,
|