Skip to main content

dental-detector

PyPI version Python License: MIT Tests

Tooth detection in maxilla and mandible dental images using YOLOv8.

dental-detector is a lightweight, open-source Python package that wraps a YOLOv8 model trained to locate and classify teeth in dental radiographs and photographs. It detects 7 tooth types across both arches and ships with a clean Python API and a CLI.

Detected classes

Class ID Tooth
0 1st Molar
1 1st Premolar
2 2nd Molar
3 2nd Premolar
4 Canine
5 Central Incisor
6 Lateral Incisor

Installation

pip install dental-detector

Note: You must supply your own trained YOLOv8 weights (.pt file). The package does not bundle a model; it provides the inference wrapper.

Quick start

from dental_detector import DentalDetector

detector = DentalDetector("best.pt")

# --- Detect ---
result = detector.detect("xray_maxilla.jpg")
print(f"Found {len(result)} teeth")
for tooth in result:
    print(tooth.label, tooth.confidence, tooth.bbox)

# --- Annotate and save ---
annotated = detector.annotate("xray_maxilla.jpg")   # PIL Image
annotated.save("annotated.jpg")

# or in one step:
detector.annotate_and_save("xray_maxilla.jpg", "annotated.jpg")

# --- Export as JSON ---
json_str = detector.detect_to_json("xray_mandible.jpg")
print(json_str)

Working with PIL / numpy directly

from PIL import Image
import numpy as np

pil_img = Image.open("xray.jpg")
result = detector.detect(pil_img)

arr = np.array(pil_img)         # RGB numpy array also works
result = detector.detect(arr)

Confidence threshold

# Set at construction time
detector = DentalDetector("best.pt", conf_threshold=0.7)

# Or override per call
result = detector.detect("xray.jpg", conf_threshold=0.5)

Filtering results

# Keep only molars
molars = result.filter_by_label("1st Molar")

# Keep high-confidence detections
high_conf = result.filter_by_confidence(0.85)

# Unique tooth types present in the image
print(result.unique_labels)

Command-line interface

# Print detected teeth
dental-detector xray.jpg --model best.pt

# Save annotated image
dental-detector xray.jpg --model best.pt --output annotated.jpg

# Output as JSON
dental-detector xray.jpg --model best.pt --json

# Set confidence threshold
dental-detector xray.jpg --model best.pt --conf 0.7

API reference

DentalDetector

Method Returns Description
detect(image, conf_threshold=None) DetectionResult Run detection
annotate(image, ...) PIL.Image Detect + draw boxes
annotate_and_save(image, path, ...) Path Detect, draw, save
detect_to_json(image, ...) str Detections as JSON

DetectionResult

Attribute / Method Description
detections list[Detection]
labels All label strings
unique_labels Sorted unique labels
filter_by_label(label) Returns filtered DetectionResult
filter_by_confidence(threshold) Returns filtered DetectionResult
to_dict() Serializable dict

Detection

Attribute Type Description
label str Tooth class name
class_id int Class index (0–6)
confidence float Model confidence (0–1)
bbox tuple[float, float, float, float] (x1, y1, x2, y2) pixels
center tuple[float, float] Bounding box center
width / height / area float Bounding box dimensions

Development

git clone https://github.com/sandeepvissa/dental-detector
cd dental-detector
pip install -e ".[dev]"

# Run tests
pytest

# Lint
ruff check dental_detector tests

License

MIT — see LICENSE.

Metadata

Release files for dental-detector 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dental-detector 0.1.1
File Size Uploaded Provenance Actions
dental_detector-0.1.1.tar.gz 11.2 kB Without provenance Details for dental_detector-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dental-detector 0.1.1
File Interpreter ABI Platform Actions
dental_detector-0.1.1-py3-none-any.whl Python 3 none any Details for dental_detector-0.1.1-py3-none-any.whl

Total release size: 22.0 kB

Release files / dental_detector-0.1.1.tar.gz

Download URL dental_detector-0.1.1.tar.gz
Size 11.2 kB
Tags Source
SHA-256 checksum
How to use checksums
3d52855be37944796feddd5ecef69fb99e0f8adfc609cce3377ac0a393e57b21
BLAKE2b-256 checksum
How to use checksums
a845dbd70291ade001ea651fc2823c7b06e163c3822b8a1245e9954857b39627
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / dental_detector-0.1.1-py3-none-any.whl

Download URL dental_detector-0.1.1-py3-none-any.whl
Size 10.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8f3e9e76d1aac638a75d98b4f60c06148848d9602656e3cf177c21370e15622b
BLAKE2b-256 checksum
How to use checksums
05db589e9007123c8e3adbd04db3086b6f7a3ac61242078d83c0e5f9928ca32d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Security for dental-detector 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page