Spaces:
Runtime error
Runtime error
Commit
路
7c117c8
1
Parent(s):
dd4cd20
Update app.py
Browse files
app.py
CHANGED
@@ -1,70 +1,37 @@
|
|
1 |
import streamlit as st
|
2 |
-
|
3 |
-
# import tensorflow as tf
|
4 |
from PIL import Image
|
5 |
import numpy as np
|
6 |
import cv2
|
7 |
from huggingface_hub import from_pretrained_keras
|
8 |
|
|
|
9 |
|
10 |
-
|
11 |
-
# model=from_pretrained_keras("SerdarHelli/Segmentation-of-Teeth-in-Panoramic-X-ray-Image-Using-U-Net")
|
12 |
-
# except:
|
13 |
-
# model=tf.keras.models.load_model("dental_xray_seg.h5")
|
14 |
-
# pass
|
15 |
-
|
16 |
-
model=from_pretrained_keras("SerdarHelli/Segmentation-of-Teeth-in-Panoramic-X-ray-Image-Using-U-Net")
|
17 |
-
|
18 |
-
st.header("Segmentation of Teeth in Panoramic X-ray Image Using UNet")
|
19 |
-
|
20 |
-
# examples=["107.png","108.png","109.png"]
|
21 |
|
22 |
-
|
|
|
|
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
|
|
|
26 |
|
|
|
27 |
def convert_one_channel(img):
|
28 |
-
|
29 |
-
if len(img.shape)>2:
|
30 |
img= cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
31 |
return img
|
32 |
else:
|
33 |
return img
|
34 |
-
|
35 |
-
def convert_rgb(img):
|
36 |
-
#some images have 3 channels , although they are grayscale image
|
37 |
-
if len(img.shape)==2:
|
38 |
-
img= cv2.cvtColor(img,cv2.COLOR_GRAY2RGB)
|
39 |
-
return img
|
40 |
-
else:
|
41 |
-
return img
|
42 |
-
|
43 |
|
44 |
st.subheader("Upload Dental Panoramic X-ray Image Image")
|
45 |
image_file = st.file_uploader("Upload Images", type=["png","jpg","jpeg"])
|
46 |
|
47 |
-
|
48 |
-
# col1, col2, col3 = st.columns(3)
|
49 |
-
# with col1:
|
50 |
-
# ex=load_image(examples[0])
|
51 |
-
# st.image(ex,width=200)
|
52 |
-
# if st.button('Example 1'):
|
53 |
-
# image_file=examples[0]
|
54 |
-
|
55 |
-
# with col2:
|
56 |
-
# ex1=load_image(examples[1])
|
57 |
-
# st.image(ex1,width=200)
|
58 |
-
# if st.button('Example 2'):
|
59 |
-
# image_file=examples[1]
|
60 |
-
|
61 |
-
|
62 |
-
# with col3:
|
63 |
-
# ex2=load_image(examples[2])
|
64 |
-
# st.image(ex2,width=200)
|
65 |
-
# if st.button('Example 3'):
|
66 |
-
# image_file=examples[2]
|
67 |
-
|
68 |
|
69 |
if image_file is not None:
|
70 |
|
@@ -89,7 +56,7 @@ if image_file is not None:
|
|
89 |
mask=cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel,iterations=1 )
|
90 |
mask=cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel,iterations=1 )
|
91 |
cnts,hieararch=cv2.findContours(mask,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
|
92 |
-
output = cv2.drawContours(
|
93 |
|
94 |
|
95 |
if output is not None :
|
|
|
1 |
import streamlit as st
|
|
|
|
|
2 |
from PIL import Image
|
3 |
import numpy as np
|
4 |
import cv2
|
5 |
from huggingface_hub import from_pretrained_keras
|
6 |
|
7 |
+
st.header("Segmentaci贸n de dientes con rayos X")
|
8 |
|
9 |
+
st.markdown('''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
+
Hola estudiantes de Platzi 馃殌. Este modelo usan UNet para segmentar im谩genes
|
12 |
+
de dientos en rayos X. Se utila un modelo de Keras importado con la funci贸n
|
13 |
+
`huggingface_hub.from_pretrained_keras`. Recuerda que el Hub de Hugging Face est谩 integrado
|
14 |
+
con muchas librer铆as como Keras, scikit-learn, fastai y otras.
|
15 |
|
16 |
+
El modelo fue creado por [SerdarHelli](https://huggingface.co/SerdarHelli/Segmentation-of-Teeth-in-Panoramic-X-ray-Image-Using-U-Net).
|
17 |
|
18 |
+
''')
|
19 |
|
20 |
+
model_id = "SerdarHelli/Segmentation-of-Teeth-in-Panoramic-X-ray-Image-Using-U-Net"
|
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 convert_one_channel(img):
|
25 |
+
if len(img.shape)>1:
|
|
|
26 |
img= cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
27 |
return img
|
28 |
else:
|
29 |
return img
|
30 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
st.subheader("Upload Dental Panoramic X-ray Image Image")
|
33 |
image_file = st.file_uploader("Upload Images", type=["png","jpg","jpeg"])
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
if image_file is not None:
|
37 |
|
|
|
56 |
mask=cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel,iterations=1 )
|
57 |
mask=cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel,iterations=1 )
|
58 |
cnts,hieararch=cv2.findContours(mask,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
|
59 |
+
output = cv2.drawContours(convert_one_channel(img), cnts, -1, (255, 0, 0) , 3)
|
60 |
|
61 |
|
62 |
if output is not None :
|