# erdanc/tooth-and-alveolar-bone-segmentation-from-cbct architecture

> Architecture diagram of the GitHub repository erdanc/tooth-and-alveolar-bone-segmentation-from-cbct, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/erdanc/tooth-and-alveolar-bone-segmentation-from-cbct
- Repository: https://github.com/erdanc/tooth-and-alveolar-bone-segmentation-from-cbct

## Overview

##### Project Type and Purpose
- This is an open-source AI pipeline (no UI) for fully automatic tooth and alveolar bone segmentation from cone-beam CT (CBCT) volumes.
- It comprises a multi-stage deep learning workflow: ROI (region of interest) localization, tooth detection, single-tooth segmentation, and instance-level post-processing.

##### File-Structure Analysis
- Top-level scripts:
- cnt_skl_dect.py (skeleton/count-skeleton detection)
- roi_dect.py (entry point for ROI localization)
- ins_tooth_seg.py (entry point for instance-level segmentation)
- test.py (inference orchestration)
- networks/
- Reusable VNet-based architectures for segmentation.
- roi_localization/
- dataloaders/ (binary mask generation, ToothLoader)
- networks/ (VNet model definition)
- train.py (ROI-localization training loop)
- utils/ (loss functions, learning-rate ramps, general utilities)
- tooth_detection/
- dataloaders/ (skeleton extraction, data generation, ToothLoader)
- networks/ (centroid_cluster, Simaese landmark net, VNet)
- train.py (tooth detection training loop)
- utils/ (losses, ramps, thin-plate spline, util)
- single tooth segmentation/
- dataloaders/ (singleToothLoader)
- networks/ (per-tooth segmentation architectures)
- train_singleTooth_segmentation.py
- utils/ (losses, ramps, thin-plate spline, util)

##### README Insights
- Deep-learning stack: PyTorch 1.4.0.
- Training and inference procedures split into stages, with separate scripts.
- Input: .nii.gz CBCT files; output: segmented masks for bone and individual teeth.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Input and Preprocessing
    DataInput["CBCT Volumes (.nii.gz)"]:::external
    Preproc["Preprocessing / Dataloaders"]:::data
    DataInput -->|".nii.gz volume"| Preproc

    %% Stage 1: ROI Localization
    subgraph "Stage 1: ROI Localization Module"
        direction TB
        ROI_DL["ROI Dataloader"]:::data
        ROI_Net["ROI Localization Network"]:::network
        ROI_Util["ROI Utilities (losses, ramps, util)"]:::util
        ROI_Train["roi_localization/train.py"]:::script
    end
    Preproc -->|"preprocessed data"| ROI_DL
    ROI_DL -->|"batches"| ROI_Net
    ROI_Net -->|"predicted ROI mask"| ROI_Util
    ROI_Util --> ROI_Train

    %% Stage 2: Tooth Detection
    subgraph "Stage 2: Tooth Detection Module"
        direction TB
        TD_DL["Tooth Detection Dataloader"]:::data
        TD_Net["Tooth Detection Networks"]:::network
        TD_Util["Tooth Detection Utilities"]:::util
        TD_Train["tooth_detection/train.py"]:::script
    end
    ROI_Util -->|"ROI mask + volume"| TD_DL
    TD_DL -->|"batches"| TD_Net
    TD_Net -->|"landmarks & masks"| TD_Util
    TD_Util --> TD_Train

    %% Stage 3: Single-Tooth Segmentation
    subgraph "Stage 3: Single-Tooth Segmentation Module"
        direction TB
        ST_DL["Single-Tooth Dataloader"]:::data
        ST_Net["Single-Tooth Segmentation Networks"]:::network
        ST_Util["Single-Tooth Utilities"]:::util
        ST_Train["single tooth segmentation/train_singleTooth_segmentation.py"]:::script
    end
    TD_Util -->|"cropped tooth volumes"| ST_DL
    ST_DL -->|"batches"| ST_Net
    ST_Net -->|"fine masks"| ST_Util
    ST_Util --> ST_Train

    %% Stage 4: Instance-Level Segmentation / Post-Processing
    subgraph "Stage 4: Instance-Level Segmentation / Post-Processing"
        direction TB
        INS_Net["Instance Segmentation Network"]:::network
        INS_Util["Post-Processing Utilities"]:::util
        INS_Script["ins_tooth_seg.py"]:::script
    end
    ST_Util -->|"all fine masks"| INS_Net
    INS_Net -->|"aligned & merged masks"| INS_Util
    INS_Util --> INS_Script

    %% Inference Orchestrator
    subgraph "Inference Orchestrator"
        direction TB
        Orch_Test["test.py"]:::script
        ROI_Infer["roi_dect.py"]:::script
        SKL_Infer["cnt_skl_dect.py"]:::script
    end
    Orch_Test --> ROI_Infer
    Orch_Test --> SKL_Infer
    Orch_Test --> INS_Script

    %% Shared Libraries
    subgraph "Shared Network Libraries"
        direction TB
        Shared_VNet["networks/vnet.py"]:::network
        Shared_VNetROI["networks/vnet_roi.py"]:::network
        Shared_VNetIns["networks/vnet_ins_seg.py"]:::network
    end
    Shared_VNet --> ROI_Net
    Shared_VNet --> TD_Net
    Shared_VNet --> ST_Net
    Shared_VNetIns --> INS_Net

    %% External Dependencies
    subgraph "External Dependencies"
        direction TB
        PyTorch["PyTorch 1.4.0"]:::external
        NumPy["NumPy"]:::external
        NiB["nibabel/SimpleITK"]:::external
    end
    PyTorch --> ROI_Net
    PyTorch --> TD_Net
    PyTorch --> ST_Net
    PyTorch --> INS_Net
    NumPy --> Preproc
    NiB --> Preproc

    %% Click Events
    click ROI_Train "https://github.com/erdanc/tooth-and-alveolar-bone-segmentation-from-cbct/blob/main/roi_localization/train.py"
    click ROI_DL "https://github.com/erdanc/tooth-and-alveolar-bone-segmentation-from-cbct/tree/main/roi_localization/dataloaders/"
    click ROI_Net "https://github.com/erdanc/tooth-and-alveolar-bone-segmentation-from-cbct/blob/main/roi_localization/networks/vnet.py"
    click ROI_Util "https://github.com/erdanc/tooth-and-alveolar-bone-segmentation-from-cbct/tree/main/roi_localization/utils/"
    click TD_Train "https://github.com/erdanc/tooth-and-alveolar-bone-segmentation-from-cbct/blob/main/tooth_detection/train.py"
    click TD_DL "https://github.com/erdanc/tooth-and-alveolar-bone-segmentation-from-cbct/tree/main/tooth_detection/dataloaders/"
    click TD_Net "https://github.com/erdanc/tooth-and-alveolar-bone-segmentation-from-cbct/tree/main/tooth_detection/networks/"
    click TD_Util "https://github.com/erdanc/tooth-and-alveolar-bone-segmentation-from-cbct/tree/main/tooth_detection/utils/"
    click ST_Train "https://github.com/erdanc/tooth-and-alveolar-bone-segmentation-from-cbct/blob/main/single tooth segmentation/train_singleTooth_segmentation.py"
    click ST_DL "https://github.com/erdanc/tooth-and-alveolar-bone-segmentation-from-cbct/blob/main/single tooth segmentation/dataloaders/singeToothLoader.py"
    click ST_Net "https://github.com/erdanc/tooth-and-alveolar-bone-segmentation-from-cbct/tree/main/single tooth segmentation/networks/"
    click ST_Util "https://github.com/erdanc/tooth-and-alveolar-bone-segmentation-from-cbct/tree/main/single tooth segmentation/utils/"
    click INS_Script "https://github.com/erdanc/tooth-and-alveolar-bone-segmentation-from-cbct/blob/main/ins_tooth_seg.py"
    click Shared_VNet "https://github.com/erdanc/tooth-and-alveolar-bone-segmentation-from-cbct/blob/main/networks/vnet.py"
    click Shared_VNetIns "https://github.com/erdanc/tooth-and-alveolar-bone-segmentation-from-cbct/blob/main/networks/vnet_ins_seg.py"
    click Orch_Test "https://github.com/erdanc/tooth-and-alveolar-bone-segmentation-from-cbct/blob/main/test.py"
    click ROI_Infer "https://github.com/erdanc/tooth-and-alveolar-bone-segmentation-from-cbct/blob/main/roi_dect.py"
    click SKL_Infer "https://github.com/erdanc/tooth-and-alveolar-bone-segmentation-from-cbct/blob/main/cnt_skl_dect.py"

    %% Styles
    classDef data fill:#B3D4FC,stroke:#333,stroke-width:1px;
    classDef network fill:#C6F6C6,stroke:#333,stroke-width:1px;
    classDef util fill:#FCE5CD,stroke:#333,stroke-width:1px;
    classDef script fill:#F8CECC,stroke:#333,stroke-width:1px;
    classDef external fill:#DDDDDD,stroke:#333,stroke-width:1px;
```
