Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force mask interpolation #2003

Merged
merged 6 commits into from
Oct 20, 2024
Merged

Force mask interpolation #2003

merged 6 commits into from
Oct 20, 2024

Conversation

ternaus
Copy link
Collaborator

@ternaus ternaus commented Oct 20, 2024

Fixes:

#1344
#850
#1145
#233

Summary by Sourcery

Introduce a 'mask_interpolation' parameter to allow specifying interpolation methods for masks in geometric transformations, addressing several related issues. Update tests to ensure the correct application of this new parameter.

Bug Fixes:

  • Fix mask interpolation issues in various geometric transformations by allowing specification of interpolation methods.

Enhancements:

  • Add a new parameter 'mask_interpolation' to various transformation classes to specify the interpolation algorithm for masks.

Tests:

  • Add tests to verify the correct application of mask interpolation across different transformations.

@ternaus ternaus marked this pull request as draft October 20, 2024 02:46
Copy link
Contributor

sourcery-ai bot commented Oct 20, 2024

Reviewer's Guide by Sourcery

This pull request introduces a new 'mask_interpolation' parameter to various geometric transformation classes in the Albumentations library. The change allows users to specify the interpolation method for masks separately from the main image interpolation method. This addresses several issues related to mask interpolation, particularly in cases where preserving mask values is crucial.

Class diagram for updated transformation classes with mask_interpolation

classDiagram
    class BaseDistortion {
        int border_mode
        ColorType value
        ColorType mask_value
        int mask_interpolation
        float p
        apply(img, map_x, map_y, params)
        apply_to_mask(mask, map_x, map_y, params)
    }
    class ElasticTransform {
        int alpha
        float sigma
        bool approximate
        bool same_dxdy
        int mask_interpolation
    }
    class Perspective {
        bool fit_output
        int interpolation
        int mask_interpolation
    }
    class Affine {
        ScaleFloatType scale
        ScaleFloatType translate_percent
        ScaleIntType translate_px
        ScaleFloatType rotate
        ScaleFloatType shear
        int interpolation
        int mask_interpolation
    }
    class ShiftScaleRotate {
        ScaleFloatType shift_limit
        ScaleFloatType scale_limit
        ScaleFloatType rotate_limit
        int mask_interpolation
    }
    class PiecewiseAffine {
        int mask_interpolation
    }
    class OpticalDistortion {
        int mask_interpolation
    }
    class GridDistortion {
        int mask_interpolation
    }
    class RandomScale {
        ScaleFloatType scale_limit
        int interpolation
        int mask_interpolation
    }
    class LongestMaxSize {
        int max_size
        int interpolation
        int mask_interpolation
    }
    class SmallestMaxSize {
        int max_size
        int interpolation
        int mask_interpolation
    }
    class Resize {
        int height
        int width
        int interpolation
        int mask_interpolation
    }
    class Rotate {
        SymmetricRangeType limit
        int interpolation
        int mask_interpolation
    }
    class SafeRotate {
        int mask_interpolation
    }
Loading

File-Level Changes

Change Details Files
Add 'mask_interpolation' parameter to geometric transformation classes
  • Introduce 'mask_interpolation' parameter with a default value of cv2.INTER_NEAREST
  • Update init methods to include the new parameter
  • Modify apply_to_mask methods to use the new mask_interpolation parameter
  • Update get_transform_init_args_names to include 'mask_interpolation'
albumentations/augmentations/geometric/transforms.py
albumentations/augmentations/geometric/resize.py
albumentations/augmentations/geometric/rotate.py
Implement mask interpolation support in composition classes
  • Add 'mask_interpolation' parameter to BaseCompose class
  • Implement set_mask_interpolation method to recursively set mask interpolation for nested transforms
  • Update Compose, OneOf, Sequential, and SomeOf classes to support mask interpolation
albumentations/core/composition.py
Update tests to verify mask interpolation functionality
  • Add new test cases for mask interpolation in various geometric transforms
  • Modify existing tests to include mask interpolation checks
  • Add tests for mask interpolation in composition classes
tests/test_transforms.py
tests/test_core.py
Refactor and improve existing code
  • Update docstrings to include information about the new mask_interpolation parameter
  • Refactor some classes to use more consistent initialization patterns
  • Fix minor issues and improve code style
albumentations/augmentations/blur/transforms.py
albumentations/augmentations/crops/transforms.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.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a 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. You can also use
    this command to specify where the summary should be inserted.

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 @ternaus - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

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.

tests/test_core.py Show resolved Hide resolved
@ternaus ternaus marked this pull request as ready for review October 20, 2024 03:28
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!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Testing: 2 issues found
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

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.

tests/test_core.py Show resolved Hide resolved
tests/test_transforms.py Show resolved Hide resolved
@ternaus ternaus merged commit 651d64c into main Oct 20, 2024
14 checks passed
@ternaus ternaus deleted the force_mask_interpolation branch October 20, 2024 03:31
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