# nminhmoi/projectpcb architecture

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

- Interactive diagram: https://gitdiagram.com/nminhmoi/projectpcb
- Repository: https://github.com/nminhmoi/projectpcb

## Overview

This repository is a classical-computer-vision PCB inspection prototype. Its main workflow pairs template and test images, aligns them, detects and localizes differences, then saves annotated results and defect crops. Dataset preparation and three experiment scripts support the workflow and document benchmarking capabilities. The README also describes machine-learning defect classification and richer alignment visualizations, but no corresponding runtime implementation was identified in the supplied tree or excerpts; those are noted as documented-only. Some orchestration details are supported by README statements because source excerpts are partial.

Main entry points: [`main.py`](https://github.com/nminhmoi/projectpcb/blob/main/main.py) (Pair Runner), [`dataset_utils.py`](https://github.com/nminhmoi/projectpcb/blob/main/dataset_utils.py) (Dataset Loader), [`module_detection.py`](https://github.com/nminhmoi/projectpcb/blob/main/module_detection.py) (Box & Crop Extraction), [`experiments/exp_blur_kernel.py`](https://github.com/nminhmoi/projectpcb/blob/main/experiments/exp_blur_kernel.py) (Blur Study)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Dataset Handling"]
  node_pair_builder["Pair Builder<br/>[build_pairs.py]"]
  node_manifest["Pair Manifest"]
  node_dataset_utils["Dataset Loader<br/>[dataset_utils.py]"]
end

subgraph group_vision["Inspection Pipeline"]
  node_main["Pair Runner<br/>[main.py]"]
  node_preprocess["Alignment &amp; Difference"]
  node_detection["Box &amp; Crop Extraction"]
end

subgraph group_outputs["Inspection Results"]
  node_results["Annotated Results<br/>[main.py]"]
  node_crops["Defect Crops"]
end

subgraph group_research["Benchmarking"]
  node_blur_study["Blur Study<br/>[exp_blur_kernel.py]"]
  node_feature_study["Feature Study"]
  node_binary_study["Color Binarization Study<br/>[exp_rgb2binary.py]"]
  node_classifier["ML Classification"]
end

node_operator(("Operator"))

node_operator -->|"runs inspection"| node_main
node_pair_builder -->|"writes pairs"| node_manifest
node_manifest -->|"loads pairs"| node_dataset_utils
node_main -->|"finds pairs"| node_dataset_utils
node_dataset_utils -->|"loads images"| node_main
node_main -->|"aligns and compares"| node_preprocess
node_main -->|"extracts boxes and crops"| node_detection
node_main -->|"writes annotations"| node_results
node_detection -->|"writes patches"| node_crops
node_blur_study -->|"loads pairs"| node_dataset_utils
node_blur_study -->|"checks difference"| node_preprocess
node_blur_study -->|"evaluates boxes"| node_detection
node_feature_study -->|"loads pairs"| node_dataset_utils
node_feature_study -->|"checks alignment"| node_preprocess
node_feature_study -->|"evaluates defects"| node_detection
node_binary_study -->|"loads pairs"| node_dataset_utils
node_classifier -.->|"classification stage"| node_main

click node_pair_builder "https://github.com/nminhmoi/projectpcb/blob/main/experiments/build_pairs.py"
click node_manifest "https://github.com/nminhmoi/projectpcb/tree/main/data/PKU-Market-PCB"
click node_dataset_utils "https://github.com/nminhmoi/projectpcb/blob/main/dataset_utils.py"
click node_main "https://github.com/nminhmoi/projectpcb/blob/main/main.py"
click node_preprocess "https://github.com/nminhmoi/projectpcb/blob/main/module_preprocess.py"
click node_detection "https://github.com/nminhmoi/projectpcb/blob/main/module_detection.py"
click node_results "https://github.com/nminhmoi/projectpcb/blob/main/main.py"
click node_crops "https://github.com/nminhmoi/projectpcb/blob/main/module_detection.py"
click node_blur_study "https://github.com/nminhmoi/projectpcb/blob/main/experiments/exp_blur_kernel.py"
click node_feature_study "https://github.com/nminhmoi/projectpcb/blob/main/experiments/exp_max_features.py"
click node_binary_study "https://github.com/nminhmoi/projectpcb/blob/main/experiments/exp_rgb2binary.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_pair_builder,node_manifest,node_dataset_utils toneBlue
class node_main,node_preprocess,node_detection toneAmber
class node_results,node_crops toneMint
class node_blur_study,node_feature_study,node_binary_study,node_classifier toneRose
class node_operator toneIndigo
```

## Components

### Dataset Handling

- [Pair Builder](https://github.com/nminhmoi/projectpcb/blob/main/experiments/build_pairs.py): `experiments/build_pairs.py`
- [Pair Manifest](https://github.com/nminhmoi/projectpcb/tree/main/data/PKU-Market-PCB): `data/PKU-Market-PCB`
- [Dataset Loader](https://github.com/nminhmoi/projectpcb/blob/main/dataset_utils.py): `dataset_utils.py`

### Inspection Pipeline

- [Pair Runner](https://github.com/nminhmoi/projectpcb/blob/main/main.py): `main.py`
- [Alignment & Difference](https://github.com/nminhmoi/projectpcb/blob/main/module_preprocess.py): `module_preprocess.py`
- [Box & Crop Extraction](https://github.com/nminhmoi/projectpcb/blob/main/module_detection.py): `module_detection.py`

### Inspection Results

- [Annotated Results](https://github.com/nminhmoi/projectpcb/blob/main/main.py): `main.py`
- [Defect Crops](https://github.com/nminhmoi/projectpcb/blob/main/module_detection.py): `module_detection.py`

### Benchmarking

- [Blur Study](https://github.com/nminhmoi/projectpcb/blob/main/experiments/exp_blur_kernel.py): `experiments/exp_blur_kernel.py`
- [Feature Study](https://github.com/nminhmoi/projectpcb/blob/main/experiments/exp_max_features.py): `experiments/exp_max_features.py`
- [Color Binarization Study](https://github.com/nminhmoi/projectpcb/blob/main/experiments/exp_rgb2binary.py): `experiments/exp_rgb2binary.py`
- **ML Classification**

### Other components

- **Operator**

## Connections

- Operator → Pair Runner: runs inspection (evidence: `main.py`)
- Pair Builder → Pair Manifest: writes pairs (evidence: `experiments/build_pairs.py`)
- Pair Manifest → Dataset Loader: loads pairs (evidence: `dataset_utils.py`)
- Pair Runner → Dataset Loader: finds pairs (evidence: `main.py`)
- Dataset Loader → Pair Runner: loads images (evidence: `main.py`)
- Pair Runner → Alignment & Difference: aligns and compares (evidence: `README.md`)
- Pair Runner → Box & Crop Extraction: extracts boxes and crops (evidence: `main.py`)
- Pair Runner → Annotated Results: writes annotations (evidence: `main.py`)
- Box & Crop Extraction → Defect Crops: writes patches (evidence: `module_detection.py`)
- Blur Study → Dataset Loader: loads pairs (evidence: `experiments/exp_blur_kernel.py`)
- Blur Study → Alignment & Difference: checks difference (evidence: `experiments/exp_blur_kernel.py`)
- Blur Study → Box & Crop Extraction: evaluates boxes (evidence: `experiments/exp_blur_kernel.py`)
- Feature Study → Dataset Loader: loads pairs (evidence: `experiments/exp_max_features.py`)
- Feature Study → Alignment & Difference: checks alignment (evidence: `experiments/exp_max_features.py`)
- Feature Study → Box & Crop Extraction: evaluates defects (evidence: `experiments/exp_max_features.py`)
- Color Binarization Study → Dataset Loader: loads pairs (evidence: `experiments/exp_rgb2binary.py`)
- ML Classification → Pair Runner: classification stage (evidence: `README.md`)
