Skip to content

fix: normalize panel sizes in AggregateImages composite output #1213

@Jammy2211

Description

@Jammy2211

Overview

When AggregateImages.output_to_folder combines panels from source images with different grid layouts (e.g., a 2x2 rgb.png and a 4x3 subplot_fit.png), the extracted panels have different pixel dimensions. This causes mismatched panel sizes in the final composite PNG — panels from smaller grids appear visibly smaller than those from larger grids.

The fix is to normalize all extracted panels to a common size (max width/height across all panels) before compositing, with an optional user-specified panel_size override.

Plan

  • Add a panel normalization step after extraction so all panels are resized to a common target size before compositing
  • Use the maximum width and height across all extracted panels as the default target
  • Add an optional panel_size parameter to output_to_folder for explicit user control
  • Use LANCZOS resampling to preserve image quality during resizing
  • Add tests covering mixed grid-size compositing
Detailed implementation plan

Affected Repositories

  • PyAutoFit (primary)

Work Classification

Library

Branch Survey

Repository Current Branch Dirty?
PyAutoFit main clean

Suggested branch: feature/aggregator-output-png
Worktree root: ~/Code/PyAutoLabs-wt/aggregator-output-png/ (created later by /start_library)

Implementation Steps

  1. In autofit/aggregator/summary/aggregate_images.py, add a _normalize_panel_sizes helper that takes a matrix of Image.Image and an optional panel_size tuple, computes the target size (max w/h or user-specified), and resizes all panels with LANCZOS.
  2. Call _normalize_panel_sizes in output_to_folder between _matrix_for_result and _matrix_to_image.
  3. Add panel_size: Optional[Tuple[int, int]] = None parameter to output_to_folder.
  4. Add tests in test_autofit/aggregator/summary_files/test_aggregate_images.py with mixed grid sizes.

Key Files

  • autofit/aggregator/summary/aggregate_images.py — panel extraction and compositing
  • test_autofit/aggregator/summary_files/test_aggregate_images.py — tests

Original Prompt

Click to expand starting prompt

Title: AggregateImages.output_to_folder — subplots from different source images with different grid sizes produce mismatched panel sizes

Problem:

When combining subplots from two different source images that have different grid layouts, the extracted panels end up at different physical sizes in the final composite PNG.

Concrete example: I'm combining panels from rgb.png (a 2x2 grid) and subplot_fit.png (a 4x3 grid). The RGB panel is extracted at its native size from the 2x2 grid, while the fit panels are extracted from
the larger 4x3 grid. Because each source image has a different total size and grid cell count, the individual panels end up at different pixel dimensions. When they're stitched side-by-side in the output,
the RGB panel appears visibly smaller (roughly half the height/width) compared to the fit panels.

Expected behaviour:

All panels in the final composite should appear at the same size, regardless of which source image or grid layout they came from. Either:

  1. AggregateImages should automatically rescale all extracted panels to a common size before compositing, or
  2. There should be a user-facing parameter (e.g. panel_size=(width, height) or normalize_panel_size=True) that controls this.

Where to look:

  • AggregateImages class and its output_to_folder method — this is where panels from different source images are stitched together.
  • The subplot extraction logic that crops panels from the source PNGs using the Enum grid positions — this is where the panel pixel dimensions diverge because each source image has a different grid.
  • The final compositing/concatenation step where extracted panels are placed side-by-side.

Suggested fix:

After extracting all panels (from whichever source images), resize them to a common target size before concatenation. The target could be the max height/width across all panels, or user-specified. PIL's
Image.resize() with LANCZOS resampling would preserve quality.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions