Skip to content

vtablas001/image-segmentation-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tooth Segmentation in Panoramic X-Rays

I created this interactive Streamlit application that performs automatic semantic segmentation of teeth in panoramic dental X-ray images using a pretrained U-Net Convolutional Neural Network. You can upload a panoramic radiograph or use one of the built-in examples to instantly visualize segmented tooth boundaries, estimated tooth counts, and per-tooth diagnostic metrics.

Live Demo on HF Spaces Streamlit TensorFlow Python License: MIT


Table of Contents


Overview

Panoramic dental X-rays (orthopantomograms) are one of the most commonly used imaging modalities in dentistry. Manually identifying and delineating individual teeth within these images is time-consuming and subject to inter-observer variability. This project demonstrates how deep learning can automate that process, delivering pixel-level tooth segmentation with a single inference pass.

The application loads a pretrained U-Net model from Hugging Face Hub, processes the input image through a complete computer vision pipeline, and displays the segmented output alongside quantitative diagnostic metrics.


What Is Image Segmentation?

Image segmentation is a computer vision task that assigns a class label to every pixel in an image, effectively partitioning the image into meaningful regions. Unlike object detection (which draws bounding boxes) or classification (which labels the entire image), segmentation produces a dense, pixel-level map that precisely outlines the boundaries of each structure.

In the context of medical imaging, semantic segmentation is particularly valuable because clinical decisions often depend on the exact shape, area, and spatial relationships of anatomical structures.

U-Net segmentation pipeline diagram


About the Model

This demo uses the pretrained model SerdarHelli/Segmentation-of-Teeth-in-Panoramic-X-ray-Image-Using-U-Net, developed by Selahattin Serdar Helli and Andac Hamamci at the Department of Biomedical Engineering, Yeditepe University, Istanbul, Turkey.

Detail Description
Architecture U-Net (encoder-decoder CNN with skip connections)
Framework TensorFlow / Keras
Input Resolution 512 x 512 pixels, single-channel grayscale
Output Binary segmentation mask (tooth vs. background)
Dice Score 95.4% overlap on the evaluation set
Training Dataset 105 to 116 curated panoramic X-ray images (Abdi et al., 2015)
Post-processing Otsu thresholding + morphological open/close operations
Error Reduction Tooth counting error reduced from 26.8% to 6.2% via morphological filtering

The U-Net architecture (Ronneberger et al., 2015) was originally designed for biomedical image segmentation. Its symmetric encoder-decoder structure with skip connections allows the network to capture both high-level semantic context and fine-grained spatial detail, making it especially effective for tasks that require precise boundary delineation.


Features

The application provides a complete end-to-end experience for dental X-ray analysis.

Image Input allows users to upload their own panoramic X-ray in PNG, JPG, or JPEG format, or select from three built-in example images for immediate testing.

Real-time Segmentation processes the uploaded image through the U-Net model and overlays detected tooth contours directly on the original image.

Diagnostic Metrics displays three key measurements at a glance: estimated tooth count, total dental area in pixels, and average tooth area in pixels.

Detected Instances Table presents a detailed breakdown of every detected tooth, including its individual area, bounding box width, and bounding box height, displayed in an interactive dataframe.


Pipeline Architecture

The inference pipeline follows five stages:

  1. Preprocessing: The input image is converted to single-channel grayscale, resized to 512x512, and normalized to the [0, 1] range.

  2. Model Inference: The preprocessed image is passed through the U-Net, which outputs a probability map where each pixel value represents the likelihood of belonging to a tooth.

  3. Thresholding: Otsu's adaptive thresholding converts the continuous probability map into a binary mask.

  4. Morphological Refinement: Opening and closing operations with a 5x5 kernel remove small noise artifacts and fill gaps within tooth regions.

  5. Contour Extraction and Visualization: OpenCV's findContours identifies individual tooth boundaries, which are drawn on the original image and used to compute per-tooth metrics.

# Core inference logic (simplified)
model = from_pretrained_keras(model_id)

img_cv = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img_cv = cv2.resize(img_cv, (512, 512), interpolation=cv2.INTER_LANCZOS4)
img_cv = np.float32(img_cv / 255).reshape(1, 512, 512, 1)

predicted = model.predict(img_cv)[0]
predicted = cv2.resize(predicted, (original_w, original_h))

mask = np.uint8(predicted * 255)
_, mask = cv2.threshold(mask, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)

kernel = np.ones((5, 5), dtype=np.float32)
mask = cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel, iterations=1)
mask = cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel, iterations=1)

contours, _ = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
output = cv2.drawContours(img, contours, -1, (255, 0, 0), 3)

Getting Started

Prerequisites

  • Python 3.11 or higher
  • pip

Installation

# Clone the repository
git clone https://github.com/vtablas001/image-segmentation-demo.git
cd image-segmentation-demo

# Create a virtual environment (recommended)
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

Run Locally

streamlit run app.py

The application will open at http://localhost:8501.

Requirements

streamlit
huggingface_hub==0.21.4
tensorflow==2.15.0
opencv-python-headless
pandas

Key Applications

Clinical Diagnosis: Assists dental professionals in identifying tooth boundaries to detect caries, periapical lesions, or alveolar bone loss with greater consistency.

Forensic Identification: Automates the extraction of dental patterns used in forensic odontology for human identification, age estimation, or gender determination.

Treatment Planning: Provides a quantitative baseline for orthodontic and prosthodontic planning by isolating individual dental structures from the mandible and maxilla.

Education and Research: Serves as a teaching tool for students and researchers exploring medical image segmentation, U-Net architectures, and computer vision pipelines.


Technologies

  • TensorFlow / Keras: Deep learning framework for loading and running the pretrained U-Net model.
  • OpenCV: Computer vision library for image preprocessing, thresholding, morphological operations, and contour extraction.
  • Streamlit: Web application framework for building interactive ML demos.
  • Hugging Face Hub: Model hosting and deployment platform.
  • Pandas: Data manipulation library for structuring diagnostic metrics.
  • NumPy: Numerical computing library for array operations and image manipulation.

References


Acknowledgments

The pretrained model used in this demo was developed by Selahattin Serdar Helli and Andac Hamamci at the Department of Biomedical Engineering, Faculty of Engineering, Yeditepe University, Istanbul, Turkey. The original training dataset was curated by Abdi et al. (2015).


Author

Victor Tablas


This application is intended for educational and demonstration purposes only. It is not a certified medical device and should not be used for clinical diagnosis without professional oversight.

About

An interactive Streamlit application for automatic semantic segmentation of teeth in panoramic dental X-rays using a pretrained U-Net Convolutional Neural Network.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages