Spaces:
Runtime error
Runtime error
Commit
·
5cbd746
1
Parent(s):
e488440
Update app.py
Browse files
app.py
CHANGED
@@ -21,12 +21,19 @@ model_id = "SerdarHelli/Segmentation-of-Teeth-in-Panoramic-X-ray-Image-Using-U-N
|
|
21 |
model=from_pretrained_keras(model_id)
|
22 |
|
23 |
## Si una imagen tiene más de un canal entonces se convierte a escala de grises (1 canal)
|
24 |
-
def
|
25 |
-
if len(img.shape)>
|
26 |
img= cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
27 |
return img
|
28 |
else:
|
29 |
return img
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
|
32 |
image_file = st.file_uploader("Sube aquí tu imagen.", type=["png","jpg","jpeg"])
|
@@ -36,12 +43,11 @@ if image_file is not None:
|
|
36 |
|
37 |
img= Image.open(image_file)
|
38 |
|
39 |
-
st.text("Segmentando...")
|
40 |
st.image(img,width=850)
|
41 |
|
42 |
img=np.asarray(img)
|
43 |
|
44 |
-
img_cv=
|
45 |
img_cv=cv2.resize(img_cv,(512,512), interpolation=cv2.INTER_LANCZOS4)
|
46 |
img_cv=np.float32(img_cv/255)
|
47 |
|
@@ -55,7 +61,7 @@ if image_file is not None:
|
|
55 |
mask=cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel,iterations=1 )
|
56 |
mask=cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel,iterations=1 )
|
57 |
cnts,hieararch=cv2.findContours(mask,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
|
58 |
-
output = cv2.drawContours(
|
59 |
|
60 |
|
61 |
if output is not None :
|
|
|
21 |
model=from_pretrained_keras(model_id)
|
22 |
|
23 |
## Si una imagen tiene más de un canal entonces se convierte a escala de grises (1 canal)
|
24 |
+
def convertir_one_channel(img):
|
25 |
+
if len(img.shape)>2:
|
26 |
img= cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
27 |
return img
|
28 |
else:
|
29 |
return img
|
30 |
+
|
31 |
+
def convertir_rgb(img):
|
32 |
+
if len(img.shape)==2:
|
33 |
+
img= cv2.cvtColor(img,cv2.COLOR_GRAY2RGB)
|
34 |
+
return img
|
35 |
+
else:
|
36 |
+
return img
|
37 |
|
38 |
|
39 |
image_file = st.file_uploader("Sube aquí tu imagen.", type=["png","jpg","jpeg"])
|
|
|
43 |
|
44 |
img= Image.open(image_file)
|
45 |
|
|
|
46 |
st.image(img,width=850)
|
47 |
|
48 |
img=np.asarray(img)
|
49 |
|
50 |
+
img_cv=convertir_one_channel(img)
|
51 |
img_cv=cv2.resize(img_cv,(512,512), interpolation=cv2.INTER_LANCZOS4)
|
52 |
img_cv=np.float32(img_cv/255)
|
53 |
|
|
|
61 |
mask=cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel,iterations=1 )
|
62 |
mask=cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel,iterations=1 )
|
63 |
cnts,hieararch=cv2.findContours(mask,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
|
64 |
+
output = cv2.drawContours(convertir_one_channel(img), cnts, -1, (255, 0, 0) , 3)
|
65 |
|
66 |
|
67 |
if output is not None :
|