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

Fix possible bug in MotionBlur #2168

Merged
merged 2 commits into from
Nov 29, 2024
Merged

Conversation

huuquan1994
Copy link
Contributor

@huuquan1994 huuquan1994 commented Nov 24, 2024

The current MotionBlur won't work if direction_range is set to -1.0. This is because the create_motion_kernel does not handle that case, resulting in a "near zero" kernel (i.e., kernel with very few non-zero values).
Also, I updated the default value of direction_range to (-0.5, 0.5) to match the description here

I hope that my PR correctly fixes the bug. Thanks!

Summary by Sourcery

Fix the MotionBlur function to handle negative direction values and update the default direction_range for consistency.

Bug Fixes:

  • Fix the MotionBlur function to correctly handle negative direction values by adjusting the kernel calculation.

Enhancements:

  • Update the default value of direction_range in the MotionBlur transform to (-0.5, 0.5) for consistency with the documentation.

Copy link
Contributor

sourcery-ai bot commented Nov 24, 2024

Reviewer's Guide by Sourcery

The PR fixes a bug in the MotionBlur implementation where negative direction_range values weren't handled correctly, and updates the default direction_range to match the documentation. The fix modifies the motion kernel creation to properly handle negative directions by applying the absolute value for scaling and then negating if needed.

Sequence diagram for create_motion_kernel with negative direction

sequenceDiagram
    participant MotionBlur
    participant create_motion_kernel
    MotionBlur->>create_motion_kernel: Call with direction < 0
    create_motion_kernel->>create_motion_kernel: Calculate t = t * (1 + abs(direction))
    create_motion_kernel->>create_motion_kernel: If direction < 0, t = t * -1
    create_motion_kernel-->>MotionBlur: Return adjusted kernel
Loading

Updated class diagram for MotionBlur

classDiagram
    class MotionBlur {
        - ScaleIntType blur_limit
        - bool allow_shifted
        - tuple< float, float > angle_range
        - tuple< float, float > direction_range
        - bool | None always_apply
        - float p
        + __init__(blur_limit, allow_shifted, angle_range, direction_range, always_apply, p)
    }
    note for MotionBlur "Updated default direction_range to (-0.5, 0.5)"
Loading

File-Level Changes

Change Details Files
Modified motion kernel creation logic to handle negative direction values
  • Added absolute value handling for direction scaling
  • Added conditional negation for negative direction values
albumentations/augmentations/blur/functional.py
Updated default direction_range parameter to match documentation
  • Changed direction_range default from (-1.0, 1.0) to (-0.5, 0.5)
albumentations/augmentations/blur/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 @huuquan1994 - 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: all looks good
  • 🟢 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.

@ternaus ternaus merged commit eaa1b5f into albumentations-team:main Nov 29, 2024
14 checks passed
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