# abhistacodes/document-image-segmentation architecture

> Architecture diagram of the GitHub repository abhistacodes/document-image-segmentation, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abhistacodes/document-image-segmentation
- Repository: https://github.com/abhistacodes/document-image-segmentation

## Overview

This repository implements document-image segmentation and downstream layout-feature analysis. The documented workflow pairs PRImA images with PAGE XML, creates masks, trains and evaluates an 11-class U-Net, then extracts class-specific bottleneck vectors for prototype and visualization analysis. The sampled code confirms the U-Net, masked feature pooling, analysis helpers, plotting helpers, and shared imports. Training, dataset preparation, metrics, and persistence are documented but their implementation was not present in the sampled source; their links are therefore limited to README evidence.

Main entry points: [`uNet_Model.py`](https://github.com/abhistacodes/document-image-segmentation/blob/main/uNet_Model.py) (U-Net), [`imports.py`](https://github.com/abhistacodes/document-image-segmentation/blob/main/imports.py) (Shared Imports), [`features.py`](https://github.com/abhistacodes/document-image-segmentation/blob/main/features.py) (Class Feature Extraction), [`plots.py`](https://github.com/abhistacodes/document-image-segmentation/blob/main/plots.py) (Feature Visualization)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_segmentation["Segmentation"]
  node_mask_prep["XML Mask Preparation"]
  node_training["Training Pipeline"]
  node_unet["U-Net<br/>[uNet_Model.py]"]
  node_evaluation["Segmentation Evaluation"]
  node_predictions[("Prediction Export")]
end

subgraph group_features["Feature Analysis"]
  node_feature_extract["Class Feature Extraction<br/>[features.py]"]
  node_vectors[("Feature Vectors")]
  node_prototypes["Class Prototypes"]
  node_visualization["Feature Visualization<br/>[plots.py]"]
  node_similarity["Similarity Analysis"]
end

subgraph group_shared["Shared Utilities"]
  node_imports["Shared Imports<br/>[imports.py]"]
end

node_prima[("PRImA Dataset")]
node_page_xml["PAGE XML"]

node_prima -->|"supplies images"| node_mask_prep
node_page_xml -->|"supplies annotations"| node_mask_prep
node_mask_prep -->|"provides masks"| node_training
node_training -->|"trains"| node_unet
node_unet -->|"produces logits"| node_evaluation
node_evaluation -->|"exports masks"| node_predictions
node_unet -->|"returns bottleneck"| node_feature_extract
node_feature_extract -->|"pools features"| node_vectors
node_vectors -->|"averages by class"| node_prototypes
node_vectors -->|"visualizes"| node_visualization
node_vectors -.->|"analyzes similarity"| node_similarity
node_feature_extract -->|"imports"| node_imports
node_unet -->|"imports"| node_imports
node_visualization -->|"imports"| node_imports
node_similarity -->|"imports"| node_imports

click node_unet "https://github.com/abhistacodes/document-image-segmentation/blob/main/uNet_Model.py"
click node_feature_extract "https://github.com/abhistacodes/document-image-segmentation/blob/main/features.py"
click node_visualization "https://github.com/abhistacodes/document-image-segmentation/blob/main/plots.py"
click node_similarity "https://github.com/abhistacodes/document-image-segmentation/blob/main/features_analysis.py"
click node_imports "https://github.com/abhistacodes/document-image-segmentation/blob/main/imports.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_mask_prep,node_training,node_unet,node_evaluation,node_predictions toneBlue
class node_feature_extract,node_vectors,node_prototypes,node_visualization,node_similarity,node_prima toneAmber
class node_imports toneMint
class node_page_xml toneIndigo
```

## Components

### Segmentation

- **XML Mask Preparation**
- **Training Pipeline**
- [U-Net](https://github.com/abhistacodes/document-image-segmentation/blob/main/uNet_Model.py): `uNet_Model.py`
- **Segmentation Evaluation**
- **Prediction Export**

### Feature Analysis

- [Class Feature Extraction](https://github.com/abhistacodes/document-image-segmentation/blob/main/features.py): `features.py`
- **Feature Vectors**
- **Class Prototypes**
- [Feature Visualization](https://github.com/abhistacodes/document-image-segmentation/blob/main/plots.py): `plots.py`
- [Similarity Analysis](https://github.com/abhistacodes/document-image-segmentation/blob/main/features_analysis.py): `features_analysis.py`

### Shared Utilities

- [Shared Imports](https://github.com/abhistacodes/document-image-segmentation/blob/main/imports.py): `imports.py`

### Other components

- **PRImA Dataset**
- **PAGE XML**

## Connections

- PRImA Dataset → XML Mask Preparation: supplies images (evidence: `README.md`)
- PAGE XML → XML Mask Preparation: supplies annotations (evidence: `README.md`)
- XML Mask Preparation → Training Pipeline: provides masks (evidence: `README.md`)
- Training Pipeline → U-Net: trains (evidence: `README.md`)
- U-Net → Segmentation Evaluation: produces logits (evidence: `README.md`)
- Segmentation Evaluation → Prediction Export: exports masks (evidence: `README.md`)
- U-Net → Class Feature Extraction: returns bottleneck (evidence: `features.py`)
- Class Feature Extraction → Feature Vectors: pools features (evidence: `README.md`)
- Feature Vectors → Class Prototypes: averages by class (evidence: `README.md`)
- Feature Vectors → Feature Visualization: visualizes (evidence: `README.md`)
- Feature Vectors → Similarity Analysis: analyzes similarity
- Class Feature Extraction → Shared Imports: imports (evidence: `features.py`)
- U-Net → Shared Imports: imports (evidence: `uNet_Model.py`)
- Feature Visualization → Shared Imports: imports (evidence: `plots.py`)
- Similarity Analysis → Shared Imports: imports (evidence: `features_analysis.py`)
