# preethamam/afmm-skeletonization architecture

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

- Interactive diagram: https://gitdiagram.com/preethamam/afmm-skeletonization
- Repository: https://github.com/preethamam/afmm-skeletonization

## Overview

##### Main Architectural Components
- Two Main Method Modules: • Method 1 (AFMM skeletonization based on a modified AFMM) • Method 2 (AFMM combined with tolerance-based feature transforms)
- Within Each Method: There are parallel implementations in:
- C (native, high-performance with CMake builds)
- Cython (bridging C performance with Python’s usability)
- Pybind (Python wrappers to access near-C performance)
- Native Python (more flexible but slower)
- Input/Output Handling: Use of input image files (from the images folder) and generation of output skeleton images.
- Build & Configuration Layer: CMake files, Visual Studio Code settings (.vscode directories), and setup scripts for Python (setup.py, requirements.txt).

##### Relationships and Interactions Between Components
- The user (or a driver script) provides an input image.
- The image is passed into one of the AFMM processing pipelines:
- For Method 1 and Method 2, the pipelines share a similar structure but differ in algorithmic details.
- Within each method, the available implementations (C, Cython, Pybind, Python) ultimately call the same core algorithm routines but are exposed with different interfaces.
- The underlying C modules are compiled via CMake and built within a structured build directory.
- The Python-based implementations (including those that use wrappers such as Cython and Pybind) rely on the core C code for performance-critical operations while providing an easier-to-use interface.
- Execution times and performance outputs (skeleton images) are compared across implementations and shown in the README.

##### Architectural Patterns and Design Principles
- Layered Architecture: The project is organized into layers:
- Low-Level Processing Layer: Optimized algorithms implemented in C and exposed through Cython/Pybind.
- Interface/Wrapper Layer: Python-based scripts for easier interaction and rapid testing.
- Build and Configuration Layer: Consistent use of CMake and setup scripts to manage builds across different language environments.
- Modularity: Separation into distinct folders (method_1 and method_2) each with similarly structured submodules for each target language.
- Reusability and Portability: With clearly separated build systems and language-specific folders, the project targets cross-platform compatibility (macOS, Linux, Windows).

##### Relevant Technologies, Frameworks, or Libraries
- C/CMake: For compiling the core, high-performance AFMM implementations.
- Python: For rapid prototyping and scripting of the skeletonization process.
- Cython and Pybind: To create efficient Python extensions that wrap the C implementations.
- Visual Studio Code: The .vscode configuration indicates developer tooling setups.
- Possibly external image libraries (indicated by stb_image.h and stb_image_write.h) used for reading and writing images.

- Clear Labels: Name each main component – “Method 1”, “Method 2”, and within each, the “C Implementation”, “Cython Module”, “Pybind Module”, and “Python Implementation”.
- Annotations: Include notes that capture platform-specific build details (like differences in Visual Studio Code build configurations, use of CMake) and performance metrics where relevant.
- The core algorithm layer in the middle,

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top Layer: Input
    INPUT["Input Images"]:::input
    click INPUT "https://github.com/preethamam/afmm-skeletonization/tree/main/images/"

    %% Method 1 Subgraph
    subgraph "Method 1: AFMM Skeletonization (Modified)"
        M1_C["C Implementation"]:::core
        M1_Cython["Cython Module"]:::wrapper
        M1_Pybind["Pybind Module"]:::wrapper
        M1_Python["Python Implementation"]:::wrapper
    end

    %% Method 2 Subgraph
    subgraph "Method 2: AFMM with Tolerance-Based Feature Transforms"
        M2_C["C Implementation"]:::core
        M2_Cython["Cython Module"]:::wrapper
        M2_Pybind["Pybind Module"]:::wrapper
        M2_Python["Python Implementation"]:::wrapper
    end

    %% Bottom Layer: Output
    OUTPUT["Output Skeleton Image"]:::output

    %% Build & Configuration Subgraph at the bottom
    subgraph "Build & Configuration"
        BUILD_CMAKE["CMake Build Files"]:::build
        BUILD_VSCODE["Visual Studio Code Settings"]:::build
        BUILD_SETUP["Python Setup & Requirements"]:::build
    end

    %% Data Flow: Input to Method Wrappers (Interface Layer)
    INPUT -->|"feeds"| M1_Python
    INPUT -->|"feeds"| M2_Python

    %% Within Method 1: Wrappers depend on Core
    M1_Cython -->|"calls"| M1_C
    M1_Pybind  -->|"calls"| M1_C
    M1_Python  -->|"calls"| M1_C

    %% Within Method 2: Wrappers depend on Core
    M2_Cython -->|"calls"| M2_C
    M2_Pybind  -->|"calls"| M2_C
    M2_Python  -->|"calls"| M2_C

    %% From Python Implementations to Output
    M1_Python -->|"produces"| OUTPUT
    M2_Python -->|"produces"| OUTPUT

    %% Dependencies to Build & Configuration Layer
    M1_C -->|"built with"| BUILD_CMAKE
    M2_C -->|"built with"| BUILD_CMAKE
    M1_Cython -->|"setup via"| BUILD_SETUP
    M1_Pybind  -->|"setup via"| BUILD_SETUP
    M2_Cython -->|"setup via"| BUILD_SETUP
    M2_Pybind  -->|"setup via"| BUILD_SETUP
    M1_Python -->|"config via"| BUILD_SETUP
    M2_Python -->|"config via"| BUILD_SETUP
    M1_C -->|"VSCode config"| BUILD_VSCODE
    M2_C -->|"VSCode config"| BUILD_VSCODE

    %% Click Events for Method 1 Components
    click M1_C "https://github.com/preethamam/afmm-skeletonization/tree/main/method_1/c/"
    click M1_Cython "https://github.com/preethamam/afmm-skeletonization/tree/main/method_1/cython/"
    click M1_Pybind "https://github.com/preethamam/afmm-skeletonization/tree/main/method_1/pybind/"
    click M1_Python "https://github.com/preethamam/afmm-skeletonization/tree/main/method_1/python/"

    %% Click Events for Method 2 Components
    click M2_C "https://github.com/preethamam/afmm-skeletonization/tree/main/method_2/c/"
    click M2_Cython "https://github.com/preethamam/afmm-skeletonization/tree/main/method_2/cython/"
    click M2_Pybind "https://github.com/preethamam/afmm-skeletonization/tree/main/method_2/pybind/"
    click M2_Python "https://github.com/preethamam/afmm-skeletonization/tree/main/method_2/python/"

    %% Click Events for Build & Configuration Components
    click BUILD_CMAKE "https://github.com/preethamam/afmm-skeletonization/blob/main/method_1/c/CMakeLists.txt"
    click BUILD_VSCODE "https://github.com/preethamam/afmm-skeletonization/tree/main/method_1/c/.vscode/"
    click BUILD_SETUP "https://github.com/preethamam/afmm-skeletonization/blob/main/method_1/cython/setup.py"

    %% Styles
    classDef input fill:#f9c,stroke:#333,stroke-width:2px;
    classDef output fill:#ccf,stroke:#333,stroke-width:2px;
    classDef core fill:#f66,stroke:#333,stroke-width:2px;
    classDef wrapper fill:#6f6,stroke:#333,stroke-width:2px;
    classDef build fill:#66f,stroke:#333,stroke-width:2px;
```
