import streamlit as st import tensorflow as tf from PIL import Image import numpy as np import cv2 model=tf.keras.models.load_model("dental_xray_seg.h5") st.header("Segmentation of Teeth in Panoramic X-ray Image Using UNet") link='Check Out Our Github Repo ! [link](https://github.com/SerdarHelli/Segmentation-of-Teeth-in-Panoramic-X-ray-Image-Using-U-Net)' st.markdown(link,unsafe_allow_html=True) def load_image(image_file): img = Image.open(image_file) return img def convert_one_channel(img): #some images have 3 channels , although they are grayscale image if len(img.shape)>2: img=img[:,:,0] return img else: return img st.subheader("Upload Dental Panoramic X-ray Image Image") image_file = st.file_uploader("Upload Images", type=["png","jpg","jpeg"]) if image_file is not None: file_details = {"filename":image_file.name, "filetype":image_file.type, "filesize":image_file.size} st.write(file_details) img=load_image(image_file) st.text("Making A Prediction ....") st.image(img,width=850) img=np.asarray(img) img_cv=convert_one_channel(img) img_cv=cv2.resize(img_cv,(512,512), interpolation=cv2.INTER_LANCZOS4) img_cv=np.float32(img_cv/255) img_cv=np.reshape(img_cv,(1,512,512,1)) prediction=model.predict(img_cv) predicted=prediction[0] predicted = cv2.resize(predicted, (img.shape[1],img.shape[0]), interpolation=cv2.INTER_LANCZOS4) mask=np.uint8(predicted*255)# _, mask = cv2.threshold(mask, thresh=255/2, maxval=255, type=cv2.THRESH_BINARY+cv2.THRESH_OTSU) cnts,hieararch=cv2.findContours(mask,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) output = cv2.drawContours(convert_one_channel(img), cnts, -1, (255, 0, 0) , 2) if output is not None : st.subheader("Predicted Image") st.image(output,width=850) st.text("DONE ! ....")