Asset-Frameworker/Tickets/ISSUE-013-plan.md
2025-04-29 18:26:13 +02:00

3.2 KiB

Plan to Resolve ISSUE-013: Merged Map Roughness Statistics

Objective: Reimplement the calculation and inclusion of image statistics (Min/Max/Mean) for roughness data, covering both standalone roughness maps and roughness data used as a source channel in merged maps (specifically the green channel for NRMRGH), and ensure these statistics are present in the output metadata.json file.

Proposed Changes:

  1. Modify _merge_maps_from_source:

    • Within the loop that processes each resolution for a merge rule, after successfully loading and transforming the source images into loaded_inputs_data, iterate through the inputs_mapping for the current rule.
    • Identify if any of the source map types in the inputs_mapping is 'ROUGH'.
    • If 'ROUGH' is used as a source, retrieve the corresponding loaded image data from loaded_inputs_data.
    • Calculate image statistics (Min/Max/Mean) for this ROUGH source image data using the existing _calculate_image_stats helper function.
    • Store these calculated statistics temporarily, associated with the output merged map type (e.g., 'NRMRGH') and the target channel it's mapped to (e.g., 'G').
  2. Update Asset Metadata Structure:

    • Introduce a new key in the asset's metadata dictionary (e.g., merged_map_channel_stats) to store statistics for specific channels within merged maps. This structure will hold the stats per merged map type, per channel, and per resolution (specifically the stats resolution defined in the config).
  3. Modify _generate_metadata_file:

    • When generating the final metadata.json file, retrieve the accumulated merged_map_channel_stats from the asset's metadata dictionary.
    • Include these statistics under a dedicated section in the output JSON, alongside the existing image_stats_1k for individual maps.

Data Flow for Statistics Calculation:

graph TD
    A[Source Image Files] --> B{_load_and_transform_source};
    B --> C[Resized/Transformed Image Data (float32)];
    C --> D{Is this source for a ROUGH map?};
    D -- Yes --> E{_calculate_image_stats};
    E --> F[Calculated Stats (Min/Max/Mean)];
    F --> G[Store in merged_map_channel_stats (in asset metadata)];
    C --> H{_merge_maps_from_source};
    H --> I[Merged Image Data];
    I --> J[_save_image];
    J --> K[Saved Merged Map File];
    G --> L[_generate_metadata_file];
    L --> M[metadata.json];

    subgraph Individual Map Processing
        A --> B;
        B --> C;
        C --> N{Is this an individual map?};
        N -- Yes --> E;
        E --> O[Store in image_stats_1k (in asset metadata)];
        C --> P[_save_image];
        P --> Q[Saved Individual Map File];
        O --> L;
        Q --> S[Organize Output Files];
    end

    subgraph Merged Map Processing
        A --> B;
        B --> C;
        C --> D;
        D -- Yes --> E;
        E --> G;
        C --> H;
        H --> I;
        I --> J;
        J --> K;
        K --> S;
    end

    L --> M;
    M --> S;

This plan ensures that statistics are calculated for the roughness data at the appropriate stage (after loading and transformation, before merging) and correctly included in the metadata file, addressing the issue described in ISSUE-013.