ddovidovich
commited on
Commit
•
04a4a6b
1
Parent(s):
82979eb
Verson_01
Browse files- app.py.txt +100 -0
- dental_xray_seg.h5 +3 -0
- model_weights.h5 +3 -0
- requirements.txt.txt +6 -0
- teeth_01.png +0 -0
- teeth_02.png +0 -0
- teeth_03.png +0 -0
- teeth_04.png +0 -0
- teeth_05.png +0 -0
app.py.txt
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import tensorflow as tf
|
3 |
+
from PIL import Image
|
4 |
+
import numpy as np
|
5 |
+
import cv2
|
6 |
+
|
7 |
+
|
8 |
+
model=tf.keras.models.load_model("dental_xray_seg.h5")
|
9 |
+
|
10 |
+
st.header("Segmentation of Teeth in Panoramic X-ray Image")
|
11 |
+
|
12 |
+
examples=["teeth_01.png","teeth_02.png","teeth_03.png","teeth_04.png","teeth_05.png"]
|
13 |
+
|
14 |
+
def load_image(image_file):
|
15 |
+
img = Image.open(image_file)
|
16 |
+
return img
|
17 |
+
|
18 |
+
def convert_one_channel(img):
|
19 |
+
#some images have 3 channels , although they are grayscale image
|
20 |
+
if len(img.shape)>2:
|
21 |
+
img= cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
22 |
+
return img
|
23 |
+
else:
|
24 |
+
return img
|
25 |
+
|
26 |
+
def convert_rgb(img):
|
27 |
+
#some images have 3 channels , although they are grayscale image
|
28 |
+
if len(img.shape)==2:
|
29 |
+
img= cv2.cvtColor(img,cv2.COLOR_GRAY2RGB)
|
30 |
+
return img
|
31 |
+
else:
|
32 |
+
return img
|
33 |
+
|
34 |
+
|
35 |
+
st.subheader("Upload Dental Panoramic X-ray Image Image")
|
36 |
+
image_file = st.file_uploader("Upload Images", type=["png","jpg","jpeg"])
|
37 |
+
|
38 |
+
col1, col2, col3 = st.columns(3)
|
39 |
+
with col1:
|
40 |
+
ex=load_image(examples[0])
|
41 |
+
st.image(ex,width=200)
|
42 |
+
if st.button('Example 1'):
|
43 |
+
image_file=examples[0]
|
44 |
+
|
45 |
+
with col2:
|
46 |
+
ex1=load_image(examples[1])
|
47 |
+
st.image(ex1,width=200)
|
48 |
+
if st.button('Example 2'):
|
49 |
+
image_file=examples[1]
|
50 |
+
|
51 |
+
with col3:
|
52 |
+
ex2=load_image(examples[2])
|
53 |
+
st.image(ex2,width=200)
|
54 |
+
if st.button('Example 3'):
|
55 |
+
image_file=examples[2]
|
56 |
+
|
57 |
+
with col4:
|
58 |
+
ex2=load_image(examples[3])
|
59 |
+
st.image(ex2,width=200)
|
60 |
+
if st.button('Example 4'):
|
61 |
+
image_file=examples[3]
|
62 |
+
|
63 |
+
with col5:
|
64 |
+
ex2=load_image(examples[4])
|
65 |
+
st.image(ex2,width=200)
|
66 |
+
if st.button('Example 5'):
|
67 |
+
image_file=examples[4]
|
68 |
+
|
69 |
+
if image_file is not None:
|
70 |
+
|
71 |
+
img=load_image(image_file)
|
72 |
+
|
73 |
+
st.text("Making A Prediction ....")
|
74 |
+
st.image(img,width=850)
|
75 |
+
|
76 |
+
img=np.asarray(img)
|
77 |
+
|
78 |
+
img_cv=convert_one_channel(img)
|
79 |
+
img_cv=cv2.resize(img_cv,(512,512), interpolation=cv2.INTER_LANCZOS4)
|
80 |
+
img_cv=np.float32(img_cv/255)
|
81 |
+
|
82 |
+
img_cv=np.reshape(img_cv,(1,512,512,1))
|
83 |
+
prediction=model.predict(img_cv)
|
84 |
+
predicted=prediction[0]
|
85 |
+
predicted = cv2.resize(predicted, (img.shape[1],img.shape[0]), interpolation=cv2.INTER_LANCZOS4)
|
86 |
+
mask=np.uint8(predicted*255)#
|
87 |
+
_, mask = cv2.threshold(mask, thresh=0, maxval=255, type=cv2.THRESH_BINARY+cv2.THRESH_OTSU)
|
88 |
+
kernel =( np.ones((5,5), dtype=np.float32))
|
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(convert_rgb(img), cnts, -1, (255, 0, 0) , 3)
|
93 |
+
|
94 |
+
|
95 |
+
if output is not None :
|
96 |
+
st.subheader("Predicted Image")
|
97 |
+
st.write(output.shape)
|
98 |
+
st.image(output,width=850)
|
99 |
+
|
100 |
+
st.text("DONE ! ....")
|
dental_xray_seg.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:713bde71a83c975c4597418e186080acce815e91e7d87bb8a44b80011b27864d
|
3 |
+
size 161328496
|
model_weights.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ec4f6156833a19fedd74121e826034009ec6bc6eb7956277a6dd6c74ef5ffa14
|
3 |
+
size 372567888
|
requirements.txt.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
imutils
|
2 |
+
numpy
|
3 |
+
Pillow
|
4 |
+
scipy
|
5 |
+
streamlit
|
6 |
+
tensorflow
|
teeth_01.png
ADDED
teeth_02.png
ADDED
teeth_03.png
ADDED
teeth_04.png
ADDED
teeth_05.png
ADDED