# keyuwu-cs/monohair architecture

> Architecture diagram of the GitHub repository keyuwu-cs/monohair, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/keyuwu-cs/monohair
- Repository: https://github.com/keyuwu-cs/monohair

## Overview

The system architecture should be represented as follows:

##### Main Components

a. Input Processing Layer:
- Monocular Video Input
- COLMAP Processing
- Video Preprocessing Module (video_preprocess/)

b. Core Processing Pipeline:
- Data Preparation Module
- Hair Exterior Optimization Module
- Hair Interior Inference Module
- Strands Generation Module

c. Supporting Systems:
- Multiple Neural Networks (MODNet, CDGNet, Instant-NGP)
- Template Systems (FLAME/SMPLX for human head)
- Visualization Components

##### Component Relationships

**Input → Preprocessing → Core Pipeline → Output**
- ↓          ↓             ↓            ↓
**External Dependencies    Neural Models   Visualization**

##### Specific Implementation Details

a. Preprocessing Stage:
- Video frame extraction
- COLMAP integration
- Segmentation (MODNet/CDGNet)
- Gabor filtering

b. Core Processing Stage:
- Instant-NGP initialization
- PMVO (Patch-based Multi-view Optimization)
- DeepMVSHair integration
- Strand generation

##### Technical Elements to Highlight

- Neural Network Components:
- MODNet (segmentation)
- CDGNet (segmentation)
- Instant-NGP (coarse initialization)
- DeepMVSHair (interior inference)

- Utility Systems:
- Camera calibration (camera/)
- Configuration management (configs/)
- Visualization tools

##### Important Connections

- Data flow between preprocessing and main pipeline
- Integration points with external neural networks
- Template fitting workflow
- Optimization feedback loops

##### Architectural Patterns to Emphasize

- Pipeline architecture for sequential processing
- Plugin architecture for neural network integration
- Modular design for different processing stages

Key Considerations:
##### Parallel processing capabilities where applicable

This system design should reflect the complex nature of the project while making it clear how all components work together to achieve the final 3D hair model output.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        VI[Monocular Video Input]:::input
    end

    subgraph Preprocessing
        VP["Video Preprocessing"]:::process
        CO["COLMAP Processing"]:::process
        GP["Gabor Processing"]:::process
        DP["Data Preparation"]:::process
        MP["Mask Processing"]:::process
        OP["Orientation Map"]:::process
    end

    subgraph "Neural Networks"
        MOD["MODNet"]:::neural
        CDG["CDGNet"]:::neural
        NGP["Instant-NGP"]:::neural
        DMH["DeepMVSHair"]:::neural
    end

    subgraph "Core Pipeline"
        HEO["Hair Exterior Optimization"]:::core
        HII["Hair Interior Inference"]:::core
        SG["Strands Generation"]:::core
    end

    subgraph "Supporting Systems"
        CC["Camera Calibration"]:::support
        CM["Configuration Management"]:::support
        VS["Visualization System"]:::support
        UF["Utility Functions"]:::support
        TA["Template Assets"]:::support
    end

    %% Connections
    VI --> VP
    VP --> CO
    CO --> GP
    GP --> DP
    DP --> MP
    DP --> OP
    
    MP --> MOD
    MP --> CDG
    
    MOD & CDG --> HEO
    NGP --> HEO
    HEO --> HII
    DMH --> HII
    HII --> SG
    
    CC --> CO
    CM --> HEO
    CM --> HII
    UF --> HEO
    UF --> HII
    TA --> HEO
    
    SG --> VS

    %% Click Events
    click VP "https://github.com/KeyuWu-CS/MonoHair/blob/master/video_preprocess/process_video.py"
    click DP "https://github.com/KeyuWu-CS/MonoHair/blob/master/prepare_data.py"
    click GP "https://github.com/KeyuWu-CS/MonoHair/blob/master/preprocess_capture_data/GaborFilter.py"
    click HEO "https://github.com/KeyuWu-CS/MonoHair/blob/master/PMVO.py"
    click HII "https://github.com/KeyuWu-CS/MonoHair/blob/master/infer_inner.py"
    click SG "https://github.com/KeyuWu-CS/MonoHair/blob/master/HairGrow.py"
    click MOD "https://github.com/KeyuWu-CS/MonoHair/tree/master/submodules/MODNet/"
    click CDG "https://github.com/KeyuWu-CS/MonoHair/tree/master/submodules/CDGNet/"
    click NGP "https://github.com/KeyuWu-CS/MonoHair/tree/master/submodules/instant-ngp/"
    click DMH "https://github.com/KeyuWu-CS/MonoHair/tree/master/submodules/DeepMVSHair/"
    click CC "https://github.com/KeyuWu-CS/MonoHair/tree/master/camera/"
    click CM "https://github.com/KeyuWu-CS/MonoHair/tree/master/configs/"
    click VS "https://github.com/KeyuWu-CS/MonoHair/blob/master/visualization.py"
    click UF "https://github.com/KeyuWu-CS/MonoHair/tree/master/Utils/"
    click TA "https://github.com/KeyuWu-CS/MonoHair/blob/master/assets/data/head_template.obj"
    click MP "https://github.com/KeyuWu-CS/MonoHair/blob/master/preprocess_capture_data/calc_masks.py"
    click OP "https://github.com/KeyuWu-CS/MonoHair/blob/master/preprocess_capture_data/calc_orientation_maps.py"

    %% Styles
    classDef input fill:#B3E5FC,stroke:#0288D1
    classDef process fill:#C8E6C9,stroke:#388E3C
    classDef neural fill:#FFE0B2,stroke:#F57C00
    classDef core fill:#FFCDD2,stroke:#D32F2F
    classDef support fill:#E1BEE7,stroke:#7B1FA2

    %% Legend
    subgraph Legend
        L1[Input Components]:::input
        L2[Processing Components]:::process
        L3[Neural Networks]:::neural
        L4[Core Pipeline]:::core
        L5[Supporting Systems]:::support
    end
```
