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 posterize #2180

Merged
merged 2 commits into from
Dec 7, 2024
Merged

Update posterize #2180

merged 2 commits into from
Dec 7, 2024

Conversation

ternaus
Copy link
Collaborator

@ternaus ternaus commented Dec 7, 2024

Summary by Sourcery

Enhance the 'posterize' function to support per-channel bit reduction and restrict the bit range to [1, 7] for more consistent effects.

Enhancements:

  • Update the 'posterize' function to allow specifying different bit reductions for each color channel by accepting a list of bit values.
  • Remove the option to use 8 bits in the 'posterize' function, limiting the range to [1, 7] for more consistent posterization effects.

Copy link
Contributor

sourcery-ai bot commented Dec 7, 2024

Reviewer's Guide by Sourcery

This PR updates the posterize transformation to improve its implementation and documentation. The main changes include limiting the bit range to 1-7 (removing the option for 8 bits), adding support for channel-specific bit reduction, and enhancing the documentation with detailed explanations and examples.

Updated class diagram for the Posterize transformation

classDiagram
    class Posterize {
        - num_bits: int | tuple[int, int] | list[int] | list[tuple[int, int]]
        + apply(img: np.ndarray, num_bits: Literal[1, 2, 3, 4, 5, 6, 7] | list[Literal[1, 2, 3, 4, 5, 6, 7]], **params: Any) np.ndarray
        + get_params() dict[str, Any]
    }
    note for Posterize "Updated to support channel-specific bit reduction and limit bit range to 1-7"
Loading

Updated class diagram for the posterize function

classDiagram
    class posterize {
        + posterize(img: np.ndarray, bits: Literal[1, 2, 3, 4, 5, 6, 7] | list[Literal[1, 2, 3, 4, 5, 6, 7]]) np.ndarray
    }
    note for posterize "Function updated to support channel-specific bit reduction and limit bit range to 1-7"
Loading

File-Level Changes

Change Details Files
Modified the posterize function signature and implementation
  • Changed bits parameter type to support both single value and per-channel list
  • Removed special handling for 8-bit case since it's now excluded from valid range
  • Simplified the implementation by removing redundant code paths
  • Added comprehensive docstring with detailed explanation and examples
albumentations/augmentations/functional.py
Updated the Posterize transform class to align with new function implementation
  • Modified num_bits parameter validation to use range [1, 7] instead of [1, 8]
  • Updated type hints for the apply method
  • Improved documentation to reflect new functionality and removed outdated notes
albumentations/augmentations/transforms.py
Added new constant for type definitions
  • Added SEVEN constant to types.py for consistency with other numeric constants
albumentations/core/types.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: 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.

Copy link

codecov bot commented Dec 7, 2024

Codecov Report

Attention: Patch coverage is 44.44444% with 5 lines in your changes missing coverage. Please review.

Project coverage is 89.75%. Comparing base (b1a79c2) to head (2f84f1f).
Report is 304 commits behind head on main.

Files with missing lines Patch % Lines
albumentations/augmentations/functional.py 20.00% 4 Missing ⚠️
albumentations/augmentations/transforms.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           main    #2180       +/-   ##
=========================================
+ Coverage      0   89.75%   +89.75%     
=========================================
  Files         0       47       +47     
  Lines         0     8431     +8431     
=========================================
+ Hits          0     7567     +7567     
- Misses        0      864      +864     

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

@ternaus ternaus merged commit 8ac781a into main Dec 7, 2024
16 checks passed
@ternaus ternaus deleted the update_posterize branch December 7, 2024 21:29
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