# rayees1728/sem_boundary_detection architecture

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

- Interactive diagram: https://gitdiagram.com/rayees1728/sem_boundary_detection
- Repository: https://github.com/rayees1728/sem_boundary_detection

## Overview

This repository is a Streamlit SEM/optical micrograph segmentation app. Users upload one or more images, select classical, bootstrap-training, or checkpoint inference, tune preprocessing and boundary cleanup, then inspect comparisons, statistics, and downloadable outputs. The graph includes the documented results and download capabilities, though their implementation details are not sampled; those links are therefore omitted. Edges are limited to calls documented in the README or visible in excerpts and the SOURCE INDEX.

Main entry points: [`app.py`](https://github.com/rayees1728/sem_boundary_detection/blob/main/app.py) (Streamlit interface), [`predict.py`](https://github.com/rayees1728/sem_boundary_detection/blob/main/predict.py) (CLI prediction), [`train.py`](https://github.com/rayees1728/sem_boundary_detection/blob/main/train.py) (Model training), [`preprocessing.py`](https://github.com/rayees1728/sem_boundary_detection/blob/main/preprocessing.py) (Image preprocessing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["App workflow"]
  node_app["Streamlit interface<br/>[app.py]"]
end

subgraph group_classical["Classical segmentation"]
  node_preprocess["Image preprocessing<br/>[preprocessing.py]"]
  node_otsu["Otsu baselines<br/>[otsu_baseline.py]"]
  node_watershed["Watershed labels<br/>[pseudo_labels.py]"]
  node_advanced["Advanced boundaries<br/>[boundary_v2.py]"]
end

subgraph group_learning["U-Net learning"]
  node_training["Model training<br/>[train.py]"]
  node_patches["Patch and inference data<br/>[dataset.py]"]
  node_unet["U-Net model<br/>[unet_model.py]"]
  node_cli_predict["CLI prediction<br/>[predict.py]"]
end

subgraph group_evaluation["Output and evaluation"]
  node_cleanup["Boundary cleanup and metrics<br/>[postprocessing.py]"]
  node_results["Results and comparison<br/>[app.py]"]
  node_statistics["Cross-image statistics<br/>[app.py]"]
  node_downloads["Mask and report downloads<br/>[app.py]"]
end

node_user(("Image analyst"))

node_user -->|"uploads and configures"| node_app
node_app -->|"preprocesses images"| node_preprocess
node_preprocess -->|"imports utilities"| node_advanced
node_app -->|"computes baselines"| node_otsu
node_otsu -->|"imports preprocessing"| node_preprocess
node_app -->|"generates pseudo-labels"| node_watershed
node_app -->|"uses boundary methods"| node_advanced
node_app -->|"trains bootstrap model"| node_training
node_app -->|"runs sliding inference"| node_patches
node_app -->|"loads model"| node_unet
node_app -->|"cleans predictions"| node_cleanup
node_training -->|"constructs model"| node_unet
node_training -->|"builds patch dataset"| node_patches
node_training -->|"preprocesses training images"| node_preprocess
node_training -->|"creates bootstrap targets"| node_watershed
node_cli_predict -->|"loads checkpoint model"| node_unet
node_cli_predict -->|"runs sliding inference"| node_patches
node_cli_predict -->|"preprocesses image"| node_preprocess
node_cli_predict -->|"computes baseline"| node_otsu
node_cli_predict -->|"creates fallback reference"| node_watershed
node_cli_predict -->|"cleans and scores"| node_cleanup
node_app -->|"presents results"| node_results
node_app -->|"summarizes images"| node_statistics
node_app -->|"offers exports"| node_downloads

click node_app "https://github.com/rayees1728/sem_boundary_detection/blob/main/app.py"
click node_preprocess "https://github.com/rayees1728/sem_boundary_detection/blob/main/preprocessing.py"
click node_otsu "https://github.com/rayees1728/sem_boundary_detection/blob/main/otsu_baseline.py"
click node_watershed "https://github.com/rayees1728/sem_boundary_detection/blob/main/pseudo_labels.py"
click node_advanced "https://github.com/rayees1728/sem_boundary_detection/blob/main/boundary_v2.py"
click node_training "https://github.com/rayees1728/sem_boundary_detection/blob/main/train.py"
click node_patches "https://github.com/rayees1728/sem_boundary_detection/blob/main/dataset.py"
click node_unet "https://github.com/rayees1728/sem_boundary_detection/blob/main/unet_model.py"
click node_cli_predict "https://github.com/rayees1728/sem_boundary_detection/blob/main/predict.py"
click node_cleanup "https://github.com/rayees1728/sem_boundary_detection/blob/main/postprocessing.py"
click node_results "https://github.com/rayees1728/sem_boundary_detection/blob/main/app.py"
click node_statistics "https://github.com/rayees1728/sem_boundary_detection/blob/main/app.py"
click node_downloads "https://github.com/rayees1728/sem_boundary_detection/blob/main/app.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_app toneBlue
class node_preprocess,node_otsu,node_watershed,node_advanced toneAmber
class node_training,node_patches,node_unet,node_cli_predict toneMint
class node_cleanup,node_results,node_statistics,node_downloads toneRose
class node_user toneIndigo
```

## Components

### App workflow

- [Streamlit interface](https://github.com/rayees1728/sem_boundary_detection/blob/main/app.py): `app.py`

### Classical segmentation

- [Image preprocessing](https://github.com/rayees1728/sem_boundary_detection/blob/main/preprocessing.py): `preprocessing.py`
- [Otsu baselines](https://github.com/rayees1728/sem_boundary_detection/blob/main/otsu_baseline.py): `otsu_baseline.py`
- [Watershed labels](https://github.com/rayees1728/sem_boundary_detection/blob/main/pseudo_labels.py): `pseudo_labels.py`
- [Advanced boundaries](https://github.com/rayees1728/sem_boundary_detection/blob/main/boundary_v2.py): `boundary_v2.py`

### U-Net learning

- [Model training](https://github.com/rayees1728/sem_boundary_detection/blob/main/train.py): `train.py`
- [Patch and inference data](https://github.com/rayees1728/sem_boundary_detection/blob/main/dataset.py): `dataset.py`
- [U-Net model](https://github.com/rayees1728/sem_boundary_detection/blob/main/unet_model.py): `unet_model.py`
- [CLI prediction](https://github.com/rayees1728/sem_boundary_detection/blob/main/predict.py): `predict.py`

### Output and evaluation

- [Boundary cleanup and metrics](https://github.com/rayees1728/sem_boundary_detection/blob/main/postprocessing.py): `postprocessing.py`
- [Results and comparison](https://github.com/rayees1728/sem_boundary_detection/blob/main/app.py): `app.py`
- [Cross-image statistics](https://github.com/rayees1728/sem_boundary_detection/blob/main/app.py): `app.py`
- [Mask and report downloads](https://github.com/rayees1728/sem_boundary_detection/blob/main/app.py): `app.py`

### Other components

- **Image analyst**

## Connections

- Image analyst → Streamlit interface: uploads and configures (evidence: `README.md`)
- Streamlit interface → Image preprocessing: preprocesses images (evidence: `app.py`)
- Image preprocessing → Advanced boundaries: imports utilities (evidence: `preprocessing.py`)
- Streamlit interface → Otsu baselines: computes baselines (evidence: `app.py`)
- Otsu baselines → Image preprocessing: imports preprocessing (evidence: `otsu_baseline.py`)
- Streamlit interface → Watershed labels: generates pseudo-labels (evidence: `app.py`)
- Streamlit interface → Advanced boundaries: uses boundary methods (evidence: `app.py`)
- Streamlit interface → Model training: trains bootstrap model (evidence: `app.py`)
- Streamlit interface → Patch and inference data: runs sliding inference (evidence: `app.py`)
- Streamlit interface → U-Net model: loads model (evidence: `app.py`)
- Streamlit interface → Boundary cleanup and metrics: cleans predictions (evidence: `app.py`)
- Model training → U-Net model: constructs model (evidence: `train.py`)
- Model training → Patch and inference data: builds patch dataset (evidence: `train.py`)
- Model training → Image preprocessing: preprocesses training images (evidence: `train.py`)
- Model training → Watershed labels: creates bootstrap targets (evidence: `train.py`)
- CLI prediction → U-Net model: loads checkpoint model (evidence: `predict.py`)
- CLI prediction → Patch and inference data: runs sliding inference (evidence: `predict.py`)
- CLI prediction → Image preprocessing: preprocesses image (evidence: `predict.py`)
- CLI prediction → Otsu baselines: computes baseline (evidence: `predict.py`)
- CLI prediction → Watershed labels: creates fallback reference (evidence: `predict.py`)
- CLI prediction → Boundary cleanup and metrics: cleans and scores (evidence: `predict.py`)
- Streamlit interface → Results and comparison: presents results (evidence: `README.md`)
- Streamlit interface → Cross-image statistics: summarizes images (evidence: `README.md`)
- Streamlit interface → Mask and report downloads: offers exports (evidence: `README.md`)
