Arslan7788 commited on
Commit
a118cca
1 Parent(s): 81233fe

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -99
app.py DELETED
@@ -1,99 +0,0 @@
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
- try:
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
- st.header("Dental X-RAY")
17
-
18
- examples=["107.png"]
19
- st.markdown(unsafe_allow_html=True)
20
-
21
-
22
- def load_image(image_file):
23
- img = Image.open(image_file)
24
- return img
25
-
26
- def convert_one_channel(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_BGR2GRAY)
30
- return img
31
- else:
32
- return img
33
-
34
- def convert_rgb(img):
35
- #some images have 3 channels , although they are grayscale image
36
- if len(img.shape)==2:
37
- img= cv2.cvtColor(img,cv2.COLOR_GRAY2RGB)
38
- return img
39
- else:
40
- return img
41
-
42
-
43
- st.subheader("Upload Dental X-ray Image Image Hear")
44
- image_file = st.file_uploader("Upload Images", type=["png","jpg","jpeg"])
45
-
46
-
47
- col1, col2, col3 = st.columns(3)
48
- with col1:
49
- ex=load_image(examples[0])
50
- st.image(ex,width=200)
51
- if st.button('Example 1'):
52
- image_file=examples[0]
53
-
54
- with col2:
55
- ex1=load_image(examples[1])
56
- st.image(ex1,width=200)
57
- if st.button('Example 2'):
58
- image_file=examples[1]
59
-
60
-
61
- with col3:
62
- ex2=load_image(examples[2])
63
- st.image(ex2,width=200)
64
- if st.button('Example 3'):
65
- image_file=examples[2]
66
-
67
-
68
- if image_file is not None:
69
-
70
- img=load_image(image_file)
71
-
72
- st.text("Making A Prediction ....")
73
- st.image(img,width=850)
74
-
75
- img=np.asarray(img)
76
-
77
- img_cv=convert_one_channel(img)
78
- img_cv=cv2.resize(img_cv,(512,512), interpolation=cv2.INTER_LANCZOS4)
79
- img_cv=np.float32(img_cv/255)
80
-
81
- img_cv=np.reshape(img_cv,(1,512,512,1))
82
- prediction=model.predict(img_cv)
83
- predicted=prediction[0]
84
- predicted = cv2.resize(predicted, (img.shape[1],img.shape[0]), interpolation=cv2.INTER_LANCZOS4)
85
- mask=np.uint8(predicted*255)#
86
- _, mask = cv2.threshold(mask, thresh=0, maxval=255, type=cv2.THRESH_BINARY+cv2.THRESH_OTSU)
87
- kernel =( np.ones((5,5), dtype=np.float32))
88
- mask=cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel,iterations=1 )
89
- mask=cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel,iterations=1 )
90
- cnts,hieararch=cv2.findContours(mask,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
91
- output = cv2.drawContours(convert_rgb(img), cnts, -1, (255, 0, 0) , 3)
92
-
93
-
94
- if output is not None :
95
- st.subheader("Predicted Image")
96
- st.write(output.shape)
97
- st.image(output,width=850)
98
-
99
- st.text("DONE ! ....")