SerdarHelli commited on
Commit
974cfa7
1 Parent(s): 96bc6a9

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -0
app.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ import streamlit as st
4
+
5
+ import tensorflow as tf
6
+ from PIL import Image
7
+ import numpy as np
8
+ import cv2
9
+
10
+ model=tf.keras.models.load_model("SerdarHelli/Segmentation-of-Teeth-in-Panoramic-X-ray-Image-Using-U-Net/dental_xray_seg.h5")
11
+
12
+ st.header("Segmentation of Teeth in Panoramic X-ray Image Using UNet")
13
+
14
+
15
+ link='Check Out Our Github Repo ! [link](https://github.com/SerdarHelli/Segmentation-of-Teeth-in-Panoramic-X-ray-Image-Using-U-Net)'
16
+ st.markdown(link,unsafe_allow_html=True)
17
+
18
+
19
+ def load_image(image_file):
20
+ img = Image.open(image_file)
21
+ return img
22
+
23
+ def convert_one_channel(img):
24
+ #some images have 3 channels , although they are grayscale image
25
+ if len(img.shape)>2:
26
+ img=img[:,:,0]
27
+ return img
28
+ else:
29
+ return img
30
+
31
+ st.subheader("Image")
32
+ image_file = st.file_uploader("Upload Images", type=["png","jpg","jpeg"])
33
+
34
+ if image_file is not None:
35
+ file_details = {"filename":image_file.name, "filetype":image_file.type,
36
+ "filesize":image_file.size}
37
+ st.write(file_details)
38
+ img=load_image(image_file)
39
+
40
+ st.text("Making A Prediction ....")
41
+ st.image(img,width=850)
42
+
43
+ img=np.asarray(img)
44
+
45
+ img_cv=convert_one_channel(img)
46
+ img_cv=cv2.resize(img_cv,(512,512), interpolation=cv2.INTER_LANCZOS4)
47
+ img_cv=np.float32(img_cv/255)
48
+
49
+ img_cv=np.reshape(img_cv,(1,512,512,1))
50
+ prediction=model.predict(img_cv)
51
+ predicted=prediction[0]
52
+ predicted = cv2.resize(predicted, (img.shape[1],img.shape[0]), interpolation=cv2.INTER_LANCZOS4)
53
+ mask=np.uint8(predicted*255)#
54
+ _, mask = cv2.threshold(mask, thresh=255/2, maxval=255, type=cv2.THRESH_BINARY+cv2.THRESH_OTSU)
55
+ cnts,hieararch=cv2.findContours(mask,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
56
+ output = cv2.drawContours(convert_one_channel(img), cnts, -1, (255, 0, 0) , 2)
57
+
58
+ if output is not None :
59
+ st.subheader("Predicted Image")
60
+ st.image(output,width=850)
61
+
62
+ st.text("DONE ! ....")
63
+
64
+