# ofir1080/hole-filling-algorithm architecture

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

- Interactive diagram: https://gitdiagram.com/ofir1080/hole-filling-algorithm
- Repository: https://github.com/ofir1080/hole-filling-algorithm

## Overview

##### Project Type and Purpose
- This is a standalone Java command-line application/library for “hole filling” in images.
- It reads an input image and a mask, detects regions marked as holes, applies a numeric algorithm to fill those holes, and outputs the filled image.

##### File Structure Analysis
- Top-level build and config:
- build.gradle, gradlew scripts → Gradle build and run
- settings.gradle, config/ → any project-wide configuration
- Source code under src/main/java:
- cmdutil/Main.java, WeightFunction.java → CLI entry point and weight calculation utility
- holefill/ → core image-processing modules:
– Image.java: image data abstraction (pixel grid, masks)
– ImageProcess.java: preprocessing (grayscale, normalization), hole boundary detection
– FillHoleCalc.java: core hole-filling algorithm (per-pixel computation)
– Point.java: coordinate data type
- Tests under src/test/java/holefill:
- ImageProcessTest.java → JUnit tests for hole boundary detection and perhaps other utilities

##### Key Architectural Patterns
- Modular separation:
- “cmdutil” package: user interface layer (argument parsing, orchestration)
- “holefill” package: domain layer (image representation + processing)
- Single-process, synchronous pipeline: CLI → load → preprocess → detect → fill → write
- Extensibility point: WeightFunction abstraction injected into FillHoleCalc

##### Main Components
a. CLI Interface (cmdutil/Main)
- Parses args: paths, algorithm parameters (z, epsilon, connectivity)
- Orchestrates calls into ImageProcess and FillHoleCalc
b. Image I/O Module
- Reads source and mask images from disk
- Converts to internal Image objects (grayscale + normalization)
- Writes filled image back to disk
c. Preprocessing (ImageProcess)
- Grayscale conversion
- Normalization to [0.0–1.0] and marking holes with –1
- Boundary detection (4- or 8-connectivity)
d. Hole-Filling Core (FillHoleCalc + WeightFunction)
- Iterates hole pixels
- Applies weight function to boundary pixels
- Computes new pixel values
e. Post-processing
- Maps normalized pixel values back to 0–255
- Integrates filled pixels into final image buffer
f. External/Supporting Services
- File System (disk I/O)
- Gradle (build/run)
- JUnit (testing)

##### Architectural Patterns & Principles
- Single Responsibility: each class/package handles one concern
- Pipeline pattern: sequential processing stages
- Dependency inversion for weight function (allows swapping different weighting strategies)
- Clear separation between I/O, processing, and orchestration

##### Capturing Essential Elements
- Don’t over-decompose: focus on these layers rather than every single class
- Where external dependencies (Gradle, JUnit) fit into build/test workflows

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Orchestration Layer
    subgraph "Orchestration Layer (cmdutil)"
        CLI["Main (CLI Interface)"]:::cli
        WF["WeightFunction (Abstraction)"]:::cli
    end

    %% Domain Layer
    subgraph "Domain Layer (holefill)"
        IMG["Image (I/O & Abstraction)"]:::model
        PROC["ImageProcess (Preprocessing)"]:::process
        CORE["FillHoleCalc (Hole-Filling Core)"]:::process
        PT["Point (Coordinate)"]:::model
        POST["Post-processing"]:::process
    end

    %% Tests
    subgraph "Tests"
        TEST["ImageProcessTest"]:::test
    end

    %% External / Build & Config
    subgraph "External / Build & Config"
        FS["File System"]:::external
        BUILD_GRADLE["build.gradle"]:::config
        SETTINGS["settings.gradle"]:::config
        CONFIG_DIR["config/"]:::config
        Gradle["Gradle"]:::config
        JUnit["JUnit"]:::external
    end

    %% Data Flow
    CLI -->|"reads image & mask"| IMG
    IMG -->|"to preprocess"| PROC
    PROC -->|"detect boundaries"| CORE
    WF -->|"injected into"| CORE
    CORE -->|"computed pixels"| POST
    POST -->|"returns filled image"| CLI
    CLI -->|"writes output"| FS
    FS -->|"reads/writes files"| IMG

    %% Dependency / Build / Test Connections
    CLI -.-> Gradle
    PROC -.-> Gradle
    CORE -.-> Gradle
    TEST -.-> PROC
    TEST -.-> CORE
    JUnit -.-> TEST

    %% Click Events
    click CLI "https://github.com/ofir1080/hole-filling-algorithm/blob/master/src/main/java/cmdutil/Main.java"
    click WF "https://github.com/ofir1080/hole-filling-algorithm/blob/master/src/main/java/cmdutil/WeightFunction.java"
    click IMG "https://github.com/ofir1080/hole-filling-algorithm/blob/master/src/main/java/holefill/Image.java"
    click PROC "https://github.com/ofir1080/hole-filling-algorithm/blob/master/src/main/java/holefill/ImageProcess.java"
    click CORE "https://github.com/ofir1080/hole-filling-algorithm/blob/master/src/main/java/holefill/FillHoleCalc.java"
    click PT "https://github.com/ofir1080/hole-filling-algorithm/blob/master/src/main/java/holefill/Point.java"
    click TEST "https://github.com/ofir1080/hole-filling-algorithm/blob/master/src/test/java/holefill/ImageProcessTest.java"
    click BUILD_GRADLE "https://github.com/ofir1080/hole-filling-algorithm/blob/master/build.gradle"
    click SETTINGS "https://github.com/ofir1080/hole-filling-algorithm/blob/master/settings.gradle"
    click CONFIG_DIR "https://github.com/ofir1080/hole-filling-algorithm/tree/master/config/"
    
    %% Styles
    classDef cli fill:#f9f,stroke:#333,stroke-width:1px;
    classDef process fill:#bbf,stroke:#333,stroke-width:1px,shape:roundrect;
    classDef model fill:#bfb,stroke:#333,stroke-width:1px;
    classDef external fill:#f99,stroke:#333,stroke-width:1px,shape:cylinder;
    classDef test fill:#ffc,stroke:#333,stroke-width:1px;
    classDef config fill:#ddd,stroke:#333,stroke-width:1px;
```
