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

Update gauss blur #2284

Merged
merged 3 commits into from
Jan 19, 2025
Merged

Update gauss blur #2284

merged 3 commits into from
Jan 19, 2025

Conversation

ternaus
Copy link
Collaborator

@ternaus ternaus commented Jan 19, 2025

Summary by Sourcery

Tests:

  • Add tests to verify Gaussian kernel creation, normalization, symmetry, peak values, and equivalence to PIL's implementation.

Copy link
Contributor

sourcery-ai bot commented Jan 19, 2025

Reviewer's Guide by Sourcery

This pull request refactors the Gaussian Blur implementation to match PIL's implementation, including kernel size calculation and kernel generation. It also adds new tests to ensure the correctness of the implementation.

Sequence diagram for updated Gaussian Blur process

sequenceDiagram
    participant Client
    participant GaussianBlur
    participant GaussianKernel
    participant Convolution

    Client->>GaussianBlur: apply_blur(image)
    GaussianBlur->>GaussianBlur: get_params()
    GaussianBlur->>GaussianKernel: create_gaussian_kernel(sigma, ksize)
    Note over GaussianKernel: New kernel creation
    Note over GaussianKernel: using PIL's approach
    GaussianKernel-->>GaussianBlur: normalized_kernel
    GaussianBlur->>Convolution: convolve(image, kernel)
    Convolution-->>GaussianBlur: blurred_image
    GaussianBlur-->>Client: blurred_image
Loading

Class diagram for updated Gaussian Blur implementation

classDiagram
    class GaussianBlur {
        +sigma_limit: tuple
        +blur_limit: tuple
        +apply(img, kernel)
        +get_params_dependent_on_data()
        +get_transform_init_args_names()
    }

    class BlurFunctional {
        +create_gaussian_kernel(sigma, ksize)
        +convolve(img, kernel)
    }

    GaussianBlur ..> BlurFunctional: uses

    note for GaussianBlur "Changed to use custom kernel"
    note for BlurFunctional "Added new kernel creation method"
Loading

File-Level Changes

Change Details Files
Refactor Gaussian blur to match PIL's implementation.
  • The kernel size calculation is changed to int(sigma * 3.5) * 2 + 1 to match PIL.
  • The Gaussian kernel generation is refactored to match PIL's approach.
  • The gaussian_blur function is removed from functional.py.
  • The apply method in GaussianBlur now takes a precomputed kernel instead of ksize and sigma.
  • The get_params_dependent_on_data method now computes the kernel and passes it to the apply method.
albumentations/augmentations/blur/transforms.py
albumentations/augmentations/blur/functional.py
Add new tests for Gaussian blur.
  • Added a helper function to create PIL's Gaussian kernel for comparison.
  • Added tests for kernel shapes, normalization, symmetry, and peak values.
  • Added a test to ensure that our kernel matches PIL's kernel.
  • Added a visual comparison test for debugging purposes.
tests/functional/test_blur.py
Remove old tests for Gaussian blur.
  • Removed tests for Gaussian blur limits.
tests/test_blur.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: 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.

Copy link

codecov bot commented Jan 19, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.85%. Comparing base (b1a79c2) to head (4af30cf).
Report is 384 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##           main    #2284       +/-   ##
=========================================
+ Coverage      0   89.85%   +89.85%     
=========================================
  Files         0       50       +50     
  Lines         0     8820     +8820     
=========================================
+ Hits          0     7925     +7925     
- Misses        0      895      +895     
Flag Coverage Δ
ubuntu-py3.12 89.85% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@ternaus ternaus merged commit 2bc1c14 into main Jan 19, 2025
16 checks passed
@ternaus ternaus deleted the update_gauss_blur branch January 19, 2025 17:26
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