# kaushik410/self_supervised_low_light_enhancer architecture

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

- Interactive diagram: https://gitdiagram.com/kaushik410/self_supervised_low_light_enhancer
- Repository: https://github.com/kaushik410/self_supervised_low_light_enhancer

## Overview

##### Project type and purpose
- This is a self-supervised, deep-learning-powered image enhancement web app.
- It lets end users upload low-light images via a Streamlit interface, applies Retinex preprocessing and a deep residual autoencoder with attention, then returns an enhanced image plus quality metrics and visualizations.

##### File structure
- app.py: Streamlit UI + orchestration (frontend + controller)
- enhancer.py: core enhancement logic (Retinex + model definition + training/inference loops)
- metrics.py: image-quality metric computations and visualizations (noise map, histograms, etc.)
- requirements.txt: Python dependencies (torch, streamlit, numpy, OpenCV, etc.)

##### README for additional insights
- Confirms usage of GPU if available (torch.cuda)
- Caches processed images to avoid redundant training
- No pretrained weights; model is trained on-the-fly per image
- Outputs NIQE, PIQE, MS-SSIM, VIF scores and visual artifacts (edge maps, frequency spectra)

a. Main components
1. User Interface (Streamlit front-end)
2. Orchestrator / Controller (app.py logic)
3. Image Preprocessing (Retinex module in enhancer.py)
4. Deep Enhancement Engine (residual autoencoder + attention in enhancer.py)
5. Metrics & Visualization Engine (metrics.py)
6. Caching Layer (Streamlit cache or on-disk storage)
7. GPU/Compute Resource (optional torch.cuda)
8. External Libraries & Frameworks (Torch, Streamlit, OpenCV, NumPy)

b. Relationships & data flow
1. User uploads an image via Streamlit UI →
2. Controller checks cache →
- if hit → load enhanced image & metrics → display
- if miss → send raw image to Preprocessing
3. Preprocessing (Retinex) → output normalized image →
4. Enhancement Engine (train/infer autoencoder) → enhanced image →
5. Metrics & Visualization Engine → compute NIQE, PIQE, MS-SSIM, VIF + generate noise & edge maps, histograms →
6. Controller aggregates results →
7. Streamlit displays enhanced image + metric scores + visualizations →
8. Optionally write to cache

c. Architectural patterns & design principles
- Layered architecture: UI layer, application/controller layer, domain logic (preprocessing + model + metrics), caching/infrastructure layer
- On-demand compute: dynamic model training per request
- Separation of concerns:
- app.py (I/O + orchestration)
- enhancer.py (image-processing + model)
- metrics.py (quality metrics + plotting)

d. Key technologies & libraries
- Python 3.x, Streamlit (UI)
- PyTorch (model training/inference)
- OpenCV / NumPy (image operations)
- Streamlit cache decorator or custom on-disk cache
- GPU acceleration via torch.cuda (if available)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Layers and Components
    subgraph "UI Layer"
        UI["User Interface\n(Streamlit UI)"]:::ui
    end

    subgraph "Application Layer"
        Controller["Orchestrator / Controller"]:::controller
        CacheDec{Cache Hit?}:::infra
    end

    subgraph "Domain Logic Layer"
        Preprocessing["Image Preprocessing\n(Retinex)"]:::domain
        Enhancement["Deep Enhancement Engine\n(Residual Autoencoder + Attention)"]:::domain
        Metrics["Metrics & Visualization Engine\n(NIQE, PIQE, MS-SSIM, VIF + Plots)"]:::metrics
    end

    subgraph "Infrastructure Layer"
        Cache[(Caching Layer)]:::infra
        GPU[(GPU Resource)]:::infra
        Dependencies[/"External Dependencies\n(Torch, Streamlit,\nOpenCV, NumPy)"/]:::infra
    end

    %% Data Flow
    UI -->|"upload raw image"| Controller
    Controller -->|“check cache”| CacheDec
    CacheDec -->|“hit: load enhanced image & metrics”| Controller
    Controller -->|“display results”| UI

    CacheDec -->|“miss”| Preprocessing
    Preprocessing -->|"normalized image"| Enhancement
    Enhancement -->|"enhanced image"| Metrics
    Metrics -->|"metrics & plots"| Controller
    Controller -->|“write to cache”| Cache
    Controller -->|“display results”| UI

    %% External Resources
    Enhancement -->|“uses GPU if available”| GPU
    Controller -->|"uses"| Dependencies
    Preprocessing -->|"uses"| Dependencies
    Metrics -->|"uses"| Dependencies

    %% Click Events
    click UI "https://github.com/kaushik410/self_supervised_low_light_enhancer/blob/main/app.py"
    click Controller "https://github.com/kaushik410/self_supervised_low_light_enhancer/blob/main/app.py"
    click Cache "https://github.com/kaushik410/self_supervised_low_light_enhancer/blob/main/app.py"
    click Preprocessing "https://github.com/kaushik410/self_supervised_low_light_enhancer/blob/main/enhancer.py"
    click Enhancement "https://github.com/kaushik410/self_supervised_low_light_enhancer/blob/main/enhancer.py"
    click Metrics "https://github.com/kaushik410/self_supervised_low_light_enhancer/blob/main/metrics.py"
    click Dependencies "https://github.com/kaushik410/self_supervised_low_light_enhancer/blob/main/requirements.txt"

    %% Styling
    classDef ui fill:#D0E6FF,stroke:#0366d6,stroke-width:1px;
    classDef controller fill:#E8F2D8,stroke:#22863a,stroke-width:1px;
    classDef domain fill:#FFF5B1,stroke:#D18616,stroke-width:1px;
    classDef metrics fill:#FFDCE0,stroke:#cb2431,stroke-width:1px;
    classDef infra fill:#F0F0F0,stroke:#6a737d,stroke-width:1px;
```
