Nada2001 commited on
Commit
a278fb4
·
1 Parent(s): 4cb24da

Delete app.py

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