# wwu-mmll/deepbet architecture

> Architecture diagram of the GitHub repository wwu-mmll/deepbet, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wwu-mmll/deepbet
- Repository: https://github.com/wwu-mmll/deepbet

## Overview

deepbet is a neural-network tool for extracting brain masks from T1-weighted MRI, exposed through a Python API, CLI, and GUI. Users select input images, output destinations, and optional threshold/dilation settings; the shared runner validates files and invokes brain extraction. Extraction uses a bounding-box model before full-resolution segmentation, then postprocesses the mask and saves requested brain images, masks, and TIV values. Utilities handle model loading, normalization, image orientation, masking, and connected components. Workflow details are based on the sampled source; the README also documents the same outputs and controls.

Main entry points: [`deepbet/bet.py`](https://github.com/wwu-mmll/deepbet/blob/main/deepbet/bet.py) (Brain Extraction), [`deepbet/utils.py`](https://github.com/wwu-mmll/deepbet/blob/main/deepbet/utils.py) (Image Operations), [`deepbet/ui/cli.py`](https://github.com/wwu-mmll/deepbet/blob/main/deepbet/ui/cli.py) (CLI), [`deepbet/ui/gui.py`](https://github.com/wwu-mmll/deepbet/blob/main/deepbet/ui/gui.py) (GUI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User Interfaces"]
  node_cli["CLI<br/>[cli.py]"]
  node_gui["GUI<br/>[gui.py]"]
end

subgraph group_workflow["Extraction Workflow"]
  node_runner["Batch Runner<br/>[bet.py]"]
  node_extraction["Brain Extraction<br/>[bet.py]"]
  node_preprocess["MRI Preparation<br/>[bet.py]"]
  node_bbox_crop["Crop Selection<br/>[bet.py]"]
  node_postprocess["Mask Postprocessing<br/>[bet.py]"]
  node_save["Output Saving<br/>[bet.py]"]
  node_results["Brain, Mask, TIV<br/>[bet.py]"]
end

subgraph group_models["Model Inference"]
  node_bbox_inference["BBox Inference<br/>[bet.py]"]
  node_bbox_model["BBox Model<br/>[bbox_model.pt]"]
  node_brain_inference["Brain Inference<br/>[bet.py]"]
  node_brain_model["Segmentation Model<br/>[model.pt]"]
end

subgraph group_utilities["Image Utilities"]
  node_validation["File Validation<br/>[utils.py]"]
  node_image_utils["Image Operations<br/>[utils.py]"]
end

node_user(("User"))
node_python_caller(("Python Caller"))
node_mri_files["MRI Files"]

node_user -->|"runs"| node_cli
node_user -->|"runs"| node_gui
node_python_caller -->|"calls"| node_runner
node_cli -->|"calls"| node_runner
node_gui -->|"calls"| node_runner
node_mri_files -->|"supplies"| node_runner
node_runner -->|"checks files"| node_validation
node_runner -->|"invokes"| node_extraction
node_extraction -->|"loads and orients"| node_preprocess
node_extraction -->|"calls"| node_bbox_inference
node_bbox_inference -->|"runs"| node_bbox_model
node_bbox_inference -->|"normalizes"| node_image_utils
node_bbox_inference -->|"selects bounds"| node_bbox_crop
node_bbox_crop -->|"sets crop"| node_brain_inference
node_brain_inference -->|"runs"| node_brain_model
node_brain_inference -->|"normalizes"| node_image_utils
node_extraction -->|"thresholds mask"| node_postprocess
node_postprocess -->|"cleans and dilates"| node_image_utils
node_extraction -->|"applies mask and reorients"| node_image_utils
node_extraction -->|"saves outputs"| node_save
node_save -->|"writes"| node_results

click node_cli "https://github.com/wwu-mmll/deepbet/blob/main/deepbet/ui/cli.py"
click node_gui "https://github.com/wwu-mmll/deepbet/blob/main/deepbet/ui/gui.py"
click node_runner "https://github.com/wwu-mmll/deepbet/blob/main/deepbet/bet.py"
click node_validation "https://github.com/wwu-mmll/deepbet/blob/main/deepbet/utils.py"
click node_extraction "https://github.com/wwu-mmll/deepbet/blob/main/deepbet/bet.py"
click node_preprocess "https://github.com/wwu-mmll/deepbet/blob/main/deepbet/bet.py"
click node_bbox_inference "https://github.com/wwu-mmll/deepbet/blob/main/deepbet/bet.py"
click node_bbox_model "https://github.com/wwu-mmll/deepbet/blob/main/data/models/bbox_model.pt"
click node_bbox_crop "https://github.com/wwu-mmll/deepbet/blob/main/deepbet/bet.py"
click node_brain_inference "https://github.com/wwu-mmll/deepbet/blob/main/deepbet/bet.py"
click node_brain_model "https://github.com/wwu-mmll/deepbet/blob/main/data/models/model.pt"
click node_postprocess "https://github.com/wwu-mmll/deepbet/blob/main/deepbet/bet.py"
click node_image_utils "https://github.com/wwu-mmll/deepbet/blob/main/deepbet/utils.py"
click node_save "https://github.com/wwu-mmll/deepbet/blob/main/deepbet/bet.py"
click node_results "https://github.com/wwu-mmll/deepbet/blob/main/deepbet/bet.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_gui,node_user toneBlue
class node_runner,node_extraction,node_preprocess,node_bbox_crop,node_postprocess,node_save,node_results toneAmber
class node_bbox_inference,node_bbox_model,node_brain_inference,node_brain_model toneMint
class node_validation,node_image_utils toneRose
class node_python_caller,node_mri_files toneIndigo
```

## Components

### User Interfaces

- [CLI](https://github.com/wwu-mmll/deepbet/blob/main/deepbet/ui/cli.py): `deepbet/ui/cli.py`
- [GUI](https://github.com/wwu-mmll/deepbet/blob/main/deepbet/ui/gui.py): `deepbet/ui/gui.py`

### Extraction Workflow

- [Batch Runner](https://github.com/wwu-mmll/deepbet/blob/main/deepbet/bet.py): `deepbet/bet.py`
- [Brain Extraction](https://github.com/wwu-mmll/deepbet/blob/main/deepbet/bet.py): `deepbet/bet.py`
- [MRI Preparation](https://github.com/wwu-mmll/deepbet/blob/main/deepbet/bet.py): `deepbet/bet.py`
- [Crop Selection](https://github.com/wwu-mmll/deepbet/blob/main/deepbet/bet.py): `deepbet/bet.py`
- [Mask Postprocessing](https://github.com/wwu-mmll/deepbet/blob/main/deepbet/bet.py): `deepbet/bet.py`
- [Output Saving](https://github.com/wwu-mmll/deepbet/blob/main/deepbet/bet.py): `deepbet/bet.py`
- [Brain, Mask, TIV](https://github.com/wwu-mmll/deepbet/blob/main/deepbet/bet.py): `deepbet/bet.py`

### Model Inference

- [BBox Inference](https://github.com/wwu-mmll/deepbet/blob/main/deepbet/bet.py): `deepbet/bet.py`
- [BBox Model](https://github.com/wwu-mmll/deepbet/blob/main/data/models/bbox_model.pt): `data/models/bbox_model.pt`
- [Brain Inference](https://github.com/wwu-mmll/deepbet/blob/main/deepbet/bet.py): `deepbet/bet.py`
- [Segmentation Model](https://github.com/wwu-mmll/deepbet/blob/main/data/models/model.pt): `data/models/model.pt`

### Image Utilities

- [File Validation](https://github.com/wwu-mmll/deepbet/blob/main/deepbet/utils.py): `deepbet/utils.py`
- [Image Operations](https://github.com/wwu-mmll/deepbet/blob/main/deepbet/utils.py): `deepbet/utils.py`

### Other components

- **User**
- **Python Caller**
- **MRI Files**

## Connections

- User → CLI: runs
- User → GUI: runs
- Python Caller → Batch Runner: calls
- CLI → Batch Runner: calls
- GUI → Batch Runner: calls
- MRI Files → Batch Runner: supplies
- Batch Runner → File Validation: checks files
- Batch Runner → Brain Extraction: invokes
- Brain Extraction → MRI Preparation: loads and orients
- Brain Extraction → BBox Inference: calls
- BBox Inference → BBox Model: runs
- BBox Inference → Image Operations: normalizes
- BBox Inference → Crop Selection: selects bounds
- Crop Selection → Brain Inference: sets crop
- Brain Inference → Segmentation Model: runs
- Brain Inference → Image Operations: normalizes
- Brain Extraction → Mask Postprocessing: thresholds mask
- Mask Postprocessing → Image Operations: cleans and dilates
- Brain Extraction → Image Operations: applies mask and reorients
- Brain Extraction → Output Saving: saves outputs
- Output Saving → Brain, Mask, TIV: writes
