Skip to content

Add automatic image resizing based on max_pixels threshold#27

Open
adamjtaylor wants to merge 3 commits into
mainfrom
claude/issue-25-20260109-1903
Open

Add automatic image resizing based on max_pixels threshold#27
adamjtaylor wants to merge 3 commits into
mainfrom
claude/issue-25-20260109-1903

Conversation

@adamjtaylor
Copy link
Copy Markdown
Owner

@adamjtaylor adamjtaylor commented Jan 9, 2026

This pull request adds a new utility function for automatic image resizing and integrates it into the image processing workflow. It also improves robustness by ensuring consistent handling of array types and adds comprehensive tests for the new resizing functionality.

New image resizing functionality:

  • Added a new function resize_if_needed in core.py to automatically downsample multi-channel images if they exceed a specified max_pixels threshold, preserving aspect ratio and data type. This function is now imported and included in the module's public API (__init__.py). [1] [2] [3]
  • Integrated resize_if_needed into the main processing workflow to ensure that images are resized before further processing or saving, preventing memory issues with large images.

Robustness and consistency improvements:

  • Updated remove_background and keep_background functions to accept both zarr.Array and np.ndarray inputs, ensuring they always operate on a numpy array internally for consistency.
  • Added the necessary import for resize from skimage.transform to support the new resizing functionality.

Testing:

  • Added comprehensive tests for resize_if_needed to verify correct behavior when resizing is not needed, when within limits, when resizing is required, and to ensure aspect ratio and data type are preserved.

- Implemented resize_if_needed() function to automatically downsample images exceeding max_pixels
- Calculates scaling factor using sqrt(max_pixels/current_pixels) to preserve aspect ratio
- Handles multi-channel data by resizing each channel separately
- Uses bilinear interpolation with anti-aliasing to prevent artifacts
- Provides user feedback via print statements when resizing occurs
- Updated remove_background() and keep_background() to handle both zarr and numpy arrays
- Added comprehensive test suite covering various scenarios
- Exported resize_if_needed in package __init__.py

Fixes #25

Co-authored-by: Adam Taylor <adamjtaylor@users.noreply.github.com>
@claude
Copy link
Copy Markdown

claude Bot commented Jan 9, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant