Skip to content
This repository was archived by the owner on Jul 10, 2025. It is now read-only.

Conversation

trylinka
Copy link
Contributor

@trylinka trylinka commented Jun 18, 2025

Summary by Sourcery

Update move_tone_curve transform to accept and propagate channel count, extend it for batched and volumetric inputs, refactor its implementation for clarity, and adjust parameter logic and tests accordingly

New Features:

  • Add num_channels parameter to tone curve transform and functional implementations
  • Introduce apply_to_images, apply_to_volume, and apply_to_volumes methods for batch and volumetric processing

Bug Fixes:

  • Fix tone curve application to correctly handle multiple channels by propagating num_channels parameter

Enhancements:

  • Extract evaluate_bez function for reuse and simplify LUT computation in move_tone_curve
  • Unify per-channel/random parameter generation using get_image_data in get_params_dependent_on_data

Tests:

  • Parameterize test_random_tone_curve to cover images and volumes and update to pass num_channels
  • Add VOLUME fixture and adjust functional tests for tone curve

Copy link
Contributor

sourcery-ai bot commented Jun 18, 2025

Reviewer's Guide

This PR refactors the tone curve adjustment by externalizing Bezier evaluation, enforcing explicit channel counts throughout the transform API, introducing spatial‐dimension utilities, and aligning tests with the new per‐channel behavior.

Entity relationship diagram for per-channel tone curve application

erDiagram
    IMAGE ||--o{ CHANNEL : has
    CHANNEL {
        float low_y
        float high_y
    }
    IMAGE {
        int num_channels
    }
Loading

Class diagram for updated tone curve transform methods

classDiagram
    class ToneCurveTransform {
        +apply(img, low_y, high_y, num_channels, **params)
        +apply_to_images(images, low_y, high_y, num_channels, **params)
        +apply_to_volume(volume, low_y, high_y, num_channels, **params)
        +apply_to_volumes(volumes, low_y, high_y, num_channels, **params)
        +get_params_dependent_on_data(data)
    }

    class fpixel {
        +move_tone_curve(img, low_y, high_y, num_channels)
        +evaluate_bez(low_y, high_y)
    }

    ToneCurveTransform --> fpixel : uses
Loading

Class diagram for new and refactored tone curve functional utilities

classDiagram
    class fpixel {
        +move_tone_curve(img, low_y, high_y, num_channels)
        +evaluate_bez(low_y, high_y)
    }

    fpixel : move_tone_curve now requires num_channels
    fpixel : evaluate_bez extracted as standalone utility
Loading

Class diagram for new spatial dimension utilities

classDiagram
    class spatial_utils {
        +get_spatial_dims_from_shape(shape)
        +construct_shape_with_spatial_dims(base_shape, spatial_dims)
        +extract_spatial_dimensions(shape) <<deprecated>>
    }
Loading

File-Level Changes

Change Details Files
Extract Bezier evaluation into a reusable helper
  • Define evaluate_bez as a top‐level function
  • Remove nested evaluate_bez within move_tone_curve
  • Update move_tone_curve calls to use the new helper
albumentations/augmentations/pixel/functional.py
Update move_tone_curve to handle explicit channel counts
  • Add num_channels parameter to the signature
  • Remove internal get_num_channels call
  • Replace cv2.merge with np.stack for multi‐channel LUT application
albumentations/augmentations/pixel/functional.py
Extend tone curve transform APIs to propagate num_channels
  • Modify apply() to pass num_channels
  • Add apply_to_images, apply_to_volume(s) methods
  • Refactor get_params_dependent_on_data to use get_image_data and include num_channels
albumentations/augmentations/pixel/transforms.py
Introduce explicit spatial dimension utilities
  • Add get_spatial_dims_from_shape and construct_shape_with_spatial_dims functions
  • Introduce extract_spatial_dimensions as a deprecated helper
  • Update transforms to leverage explicit spatial dimension handling
albumentations/utils/spatial_dims.py
albumentations/augmentations/pixel/transforms.py
Align tests with the new per‐channel API
  • Update test_random_tone_curve to accept num_channels
  • Add VOLUME fixture in conftest
  • Apply minor formatting tweaks in other tests
tests/functional/test_functional.py
tests/conftest.py

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
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 @trylinka - 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.

@trylinka
Copy link
Contributor Author

@sourcery-ai review

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 @trylinka - 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.

@ternaus ternaus merged commit 1cc07b7 into albumentations-team:main Jun 18, 2025
14 of 15 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants