# ytkz11/aerialpicturecorrection architecture

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

- Interactive diagram: https://gitdiagram.com/ytkz11/aerialpicturecorrection
- Repository: https://github.com/ytkz11/aerialpicturecorrection

## Overview

##### Main Components
- Input Module: Represent the entry point where the UAV-acquired aerial images (and associated metadata like height, focal length, sensor pixel size) are received. Files like AerialCorrection.py and photo_point_location.py indicate that the project handles image input and geospatial data extraction.
- Preprocessing & Correction Pipeline:
- Image Expansion: A module that “expands” or pads the original image (with zero values) to prepare it for rotation.
- Rotation: A dedicated component that rotates the expanded image based on the yaw angle. The README explains that this is done to avoid information loss, which clarifies that implementation avoids a direct rotation of the original image.
- Cropping: Once rotated, only the useful parts of the image are retained by cropping out the padded regions.
- Geospatial Computation:
- Calculation of spatial resolution using the formula: spatial resolution = (pixel size x height)/focal length.
- Coordinate Conversion: Convert the meter-based resolution to degrees, then compute the upper-left corner’s longitude and latitude using the given formulas.
- Affine Transformation Module:
- TIF Synthesis Module:
- Leverage the GDAL library to combine the geospatial affine parameters with the processed image, thereby generating the final georeferenced TIF.
- Image Stitching (optional/additional): The UAV-Image-stitching directory contains multiple scripts (e.g., AutomaticPanoramicImageStitching.py, UAV-image-stitching.py) that appear designed to handle image stitching operations. This may either be a separate pipeline or integrated into the overall process for broad area coverage.

##### Relationships and Data Flow
- Flow starts with the Input Module feeding raw images and metadata into the preprocessing pipeline.
- The Preprocessing & Correction Pipeline flows sequentially: Image Expansion → Rotation (with emphasis on avoiding loss by using an expanded image) → Cropping.
- The output from the preprocessing phase is fed into the Geospatial Computation component where spatial resolution and coordinate conversion logic is applied.
- Next, the Affine Transformation Module uses geospatial info to compute parameters for TIF generation.
- Finally, the TIF Synthesis Module integrates the corrected image with its georeferencing data via GDAL to produce the final output.
- Optionally, the Image Stitching components may run in parallel or as a subsequent module to create larger composite images from multiple UAV shots.

##### Architectural Patterns and Important Design Principles
- Pipeline/Sequential Processing: Clearly show distinct sequential stages (expansion → rotation → cropping → geospatial computations → georeferencing) to reflect the step-by-step processing flow.
- Modular Design: Each processing stage can be represented as a separate module/component; this modularization aids in clarity, maintainability, and unit testing.
- Clear Separation of Concerns: Data input, image processing (including computer vision elements like homography and SIFT in the stitching scripts), geospatial computations, and GIS output are segregated.

##### Relevant Technologies and Frameworks
- OpenCV: Indicated by the image operations (expansion, rotation, cropping) and mentions within the README.
- GDAL: Used for creating the synthetized georeferenced TIF format images.
- Python: Entire project is implemented in Python, as suggested by the multiple .py files.
- (Possibly) Numpy: Likely used for numerical operations and pixel/array manipulations, indicated by files like two_npy_file_to_stitching.py.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input Module Subgraph
    subgraph "Input Module"
        Input_Image["Image Acquisition"]:::input
        Input_Metadata["Geospatial Metadata Extraction"]:::input
    end

    %% Preprocessing Pipeline Subgraph
    Input_Image --> Image_Expansion
    Input_Metadata --> Image_Expansion
    subgraph "Preprocessing Pipeline"
        Image_Expansion["Image Expansion"]:::processing
        Rotation["Rotation (Yaw Correction)"]:::processing
        Cropping["Cropping"]:::processing
        Image_Expansion --> Rotation
        Rotation --> Cropping
    end

    %% Geospatial Computation Subgraph
    Cropping --> Spatial_Resolution
    subgraph "Geospatial Computation"
        Spatial_Resolution["Spatial Resolution"]:::geospatial
        Coordinate_Conversion["Coordinate Conversion"]:::geospatial
        Spatial_Resolution --> Coordinate_Conversion
    end

    %% Affine Transformation and TIF Synthesis
    Coordinate_Conversion --> Affine_Transformation["Affine Transformation"]:::geospatial
    Affine_Transformation --> TIF_Synthesis["TIF Synthesis (GDAL)"]:::geospatial

    %% Optional Image Stitching Pipeline
    Input_Image --> Stitch_Entry["Stitching Start"]:::stitching
    subgraph "Image Stitching Module"
        Stitch_Automatic["Automatic Panoramic Stitching"]:::stitching
        Stitch_UAV["UAV Image Stitching"]:::stitching
        Stitch_Homography["Homography"]:::stitching
        Stitch_OverlayAreas["Overlay Areas"]:::stitching
        Stitch_OverlaySift["Overlay SIFT"]:::stitching
        Stitch_Split["Split Left/Right"]:::stitching
        Stitch_TwoNP["Two NP File Stitching"]:::stitching
        Stitch_Warp["Warp"]:::stitching

        Stitch_Automatic --> Stitch_UAV
        Stitch_UAV --> Stitch_Homography
        Stitch_Homography --> Stitch_OverlayAreas
        Stitch_OverlayAreas --> Stitch_OverlaySift
        Stitch_OverlaySift --> Stitch_Split
        Stitch_Split --> Stitch_TwoNP
        Stitch_TwoNP --> Stitch_Warp
    end
    Stitch_Entry --> Stitch_Automatic

    %% Class Definitions for Colors
    classDef input fill:#FFA500,stroke:#000,stroke-width:2px;
    classDef processing fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef geospatial fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef stitching fill:#FFFF99,stroke:#000,stroke-width:2px;

    %% Click Events for Component Mappings
    click Input_Image "https://github.com/ytkz11/aerialpicturecorrection/blob/master/AerialCorrection.py"
    click Input_Metadata "https://github.com/ytkz11/aerialpicturecorrection/blob/master/photo_point_location.py"
    click Image_Expansion "https://github.com/ytkz11/aerialpicturecorrection/blob/master/AerialCorrection.py"
    click Rotation "https://github.com/ytkz11/aerialpicturecorrection/blob/master/AerialCorrection.py"
    click Cropping "https://github.com/ytkz11/aerialpicturecorrection/blob/master/AerialCorrection.py"
    click Spatial_Resolution "https://github.com/ytkz11/aerialpicturecorrection/blob/master/photo_point_location.py"
    click Coordinate_Conversion "https://github.com/ytkz11/aerialpicturecorrection/blob/master/create_point_gpkg.py"
    click Affine_Transformation "https://github.com/ytkz11/aerialpicturecorrection/blob/master/AerialCorrection.py"
    click TIF_Synthesis "https://github.com/ytkz11/aerialpicturecorrection/blob/master/AerialCorrection.py"
    click Stitch_Automatic "https://github.com/ytkz11/aerialpicturecorrection/blob/master/UAV-Image-stitching/AutomaticPanoramicImageStitching.py"
    click Stitch_UAV "https://github.com/ytkz11/aerialpicturecorrection/blob/master/UAV-Image-stitching/UAV-image-stitching.py"
    click Stitch_Homography "https://github.com/ytkz11/aerialpicturecorrection/blob/master/UAV-Image-stitching/homography.py"
    click Stitch_OverlayAreas "https://github.com/ytkz11/aerialpicturecorrection/blob/master/UAV-Image-stitching/overlay_image_areas.py"
    click Stitch_OverlaySift "https://github.com/ytkz11/aerialpicturecorrection/blob/master/UAV-Image-stitching/overlay_image_sift.py"
    click Stitch_Split "https://github.com/ytkz11/aerialpicturecorrection/blob/master/UAV-Image-stitching/split_left_right_image.py"
    click Stitch_TwoNP "https://github.com/ytkz11/aerialpicturecorrection/blob/master/UAV-Image-stitching/two_npy_file_to_stitching.py"
    click Stitch_Warp "https://github.com/ytkz11/aerialpicturecorrection/blob/master/UAV-Image-stitching/warp.py"
```
