Skip to content

Conversation

@ternaus
Copy link
Contributor

@ternaus ternaus commented Jun 24, 2025

Summary by Sourcery

Simplify the image normalization module by removing batch-based normalization, restricting LUT-based optimization to standard 3D images, and updating the package version.

Enhancements:

  • Restrict uint8 LUT-based normalization to 3D images for improved performance.

Tests:

  • Remove tests for the deprecated batch normalization function, retaining only per-image normalization tests.

Chores:

  • Remove the normalize_per_image_batch function and its associated imports.
  • Bump the package version to 0.0.30.

@ternaus ternaus requested a review from Copilot June 24, 2025 01:37
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jun 24, 2025

Reviewer's Guide

This PR optimizes per-image normalization by narrowing the LUT path to 3-channel uint8 images, removes the standalone batch normalization function and its tests to simplify the API, and increments the package version.

Class diagram for normalization function changes

classDiagram
    class functions {
        +normalize_per_image(img: np.ndarray, normalization: NormalizationType) np.ndarray
        -normalize_per_image_batch(images: np.ndarray, normalization: NormalizationType, spatial_axes: tuple[int, ...]) np.ndarray
        +to_float_numpy(img: np.ndarray, max_value: float | None = None) np.ndarray
    }
    functions : -normalize_per_image_batch removed
    functions : +normalize_per_image updated
    functions : +to_float_numpy unchanged
Loading

File-Level Changes

Change Details Files
Restrict LUT-based normalization to 3D images
  • Added img.ndim == 3 check to the uint8 LUT-based branch in normalize_per_image
albucore/functions.py
Remove batch normalization utility
  • Deleted normalize_per_image_batch function and its docstring
  • Removed its import and all related tests
albucore/functions.py
tests/test_normalize_per_image.py
Bump package version
  • Updated version from 0.0.29 to 0.0.30
pyproject.toml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

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 aims to speed up image normalization by refining the normalization path for single images and deprecating the batch normalization API. Key changes include:

  • Removal of the batch normalization test and its implementation.
  • Update of the normalization condition in functions.py to restrict LUT-based normalization to 3D uint8 images.
  • Version bump in pyproject.toml from 0.0.29 to 0.0.30.

Reviewed Changes

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

File Description
tests/test_normalize_per_image.py Removed tests for the deprecated batch normalization method.
pyproject.toml Updated version to reflect the new release.
albucore/functions.py Updated LUT normalization condition and removed batch normalization.
Comments suppressed due to low confidence (2)

tests/test_normalize_per_image.py:138

  • The batch normalization test and its corresponding functionality have been removed. Please update the public API documentation to reflect this change if the removal was intentional.
def test_normalize_per_image_constant(shape, normalization, dtype):

albucore/functions.py:712

  • [nitpick] The updated condition limits LUT normalization to 3D images; please update the function's docstring to clarify that non-3D images will be handled by the OpenCV implementation.
    if img.dtype == np.uint8 and normalization != "image_per_channel" and img.ndim == 3:

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @ternaus - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (main@ccd12b9). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #60   +/-   ##
=======================================
  Coverage        ?   93.97%           
=======================================
  Files           ?       17           
  Lines           ?     1793           
  Branches        ?        0           
=======================================
  Hits            ?     1685           
  Misses          ?      108           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: Grayscale Image Normalization Performance Issue

The img.ndim == 3 condition added in the normalize_per_image function (line 712) unnecessarily restricts the fast LUT optimization path. This forces 2D uint8 grayscale images (shape (H, W)) to use the slower OpenCV normalization method instead of the faster normalize_per_image_lut function, causing a performance regression. The normalize_per_image_lut function is capable of handling 2D inputs.

albucore/functions.py#L711-L712

"""
if img.dtype == np.uint8 and normalization != "image_per_channel" and img.ndim == 3:

Fix in Cursor


BugBot free trial expires on July 22, 2025
You have used $0.00 of your $20.00 spend limit so far. Manage your spend limit in the Cursor dashboard.

Was this report helpful? Give feedback by reacting with 👍 or 👎

@ternaus ternaus merged commit 2d76ea5 into main Jun 24, 2025
14 checks passed
@ternaus ternaus deleted the speedup_normalize branch June 24, 2025 01:40
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.

3 participants