How ofir1080/hole-filling-algorithm works
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