Skip to content

improve image normalization capabilities#372

Merged
sophiamaedler merged 54 commits intomainfrom
add_image_normalization
Mar 1, 2026
Merged

improve image normalization capabilities#372
sophiamaedler merged 54 commits intomainfrom
add_image_normalization

Conversation

@sophiamaedler
Copy link
Collaborator

  • Hardened image processing utilities with safer dtype handling, input validation, and logging.
  • Fixed normalization and downsampling edge cases (2D padding, divide‑by‑zero, cutoff semantics).
  • Expanded test coverage for normalization, downsampling, and rescaling paths.

Key Changes

  • percentile_normalization now correctly detects floating dtypes.
  • value_range_normalization gains validation, out_dtype, and return_float options.
  • downsample_img_padding handles 2D/3D padding correctly and uses logging.
  • rescale_image validates dtype and uses raw cutoff_threshold.
  • rolling_window_mean updated to be numba‑compatible and avoids NaNs on constant arrays.
  • Added tests for new behaviors and edge cases across normalization/downsampling/rescale paths.

Copilot AI review requested due to automatic review settings February 10, 2026 13:45
@sophiamaedler sophiamaedler changed the title Add image normalization improve image normalization capabilities Feb 10, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens and extends image normalization/downsampling utilities by improving dtype handling, adding validation options, fixing edge cases (divide-by-zero, padding semantics, cutoff handling), and expanding unit test coverage.

Changes:

  • Added value_range_normalization with range validation, out_dtype, and return_float support.
  • Fixed dtype detection in percentile_normalization, cutoff semantics in rescale_image, and edge cases in downsampling (zero max, 2D/3D padding + logging).
  • Updated rolling_window_mean to avoid NaNs on constant arrays and added tests for new behaviors.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
tests/unit_tests/processing/test_images.py Adds unit tests covering new normalization behaviors and downsampling/rescaling edge cases.
src/scportrait/processing/images/_image_processing.py Implements normalization API additions and fixes multiple edge cases; replaces prints with logging.
src/scportrait/processing/images/init.py Exposes value_range_normalization at the package level.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 9 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 47 to 52
if cutoff_threshold is not None:
if img.max() > cutoff_threshold:
_img = img.copy()
values = _img[_img < (cutoff_threshold / factor)]
values = _img[_img < cutoff_threshold]
else:
values = img
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

values is undefined when cutoff_threshold is not None and img.max() <= cutoff_threshold, causing an UnboundLocalError at the percentile calculation. Initialize values = img within the cutoff_threshold is not None branch (or add an else for the inner if) so values is always defined.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated 5 comments.

Comments suppressed due to low confidence (1)

src/scportrait/plotting/_vis.py:45

  • plot_image_array docstring says it returns None, but the function returns a Figure when return_fig=True. Update the docstring to document return_fig and the actual return type/behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sophiamaedler sophiamaedler merged commit c5e80ef into main Mar 1, 2026
2 checks passed
@sophiamaedler sophiamaedler deleted the add_image_normalization branch March 1, 2026 19:29
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.

2 participants