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

Add random jpeg #2125

Merged
merged 5 commits into from
Nov 9, 2024
Merged

Add random jpeg #2125

merged 5 commits into from
Nov 9, 2024

Conversation

ternaus
Copy link
Collaborator

@ternaus ternaus commented Nov 9, 2024

Fixes: #2097

Summary by Sourcery

Add the RandomJPEG transform for applying random JPEG compression and enhance the image_compression function to support various channel configurations. Include new tests to ensure functionality and quality consistency.

New Features:

  • Introduce the RandomJPEG transform to apply random JPEG compression to images with a specified quality range.

Enhancements:

  • Refactor the image_compression function to handle images with different channel counts more effectively, including grayscale, RGB, and images with extra channels.

Tests:

  • Add comprehensive tests for the image_compression function to verify shape preservation, quality impact, and channel consistency across different image types and qualities.

Copy link
Contributor

sourcery-ai bot commented Nov 9, 2024

Reviewer's Guide by Sourcery

This PR implements image compression functionality with support for JPEG and WebP formats, along with a new RandomJPEG transform. The implementation handles various channel configurations (grayscale, RGB, RGBA, and multi-channel images) and includes comprehensive test coverage for different image types and quality settings.

Class diagram for the new RandomJPEG class

classDiagram
    class RandomJPEG {
        +tuple[int, int] jpeg_quality
        +bool always_apply
        +float p
        +__init__(jpeg_quality: tuple[int, int] = (50, 50), always_apply: bool = False, p: float = 0.5)
        +get_transform_init_args_names() tuple[str, ...]
    }
    class ImageCompression {
        <<abstract>>
    }
    RandomJPEG --|> ImageCompression : Inherits
    note for RandomJPEG "This is a specialized version of ImageCompression configured for JPEG only."
Loading

File-Level Changes

Change Details Files
Enhanced image compression functionality to handle multiple channel configurations
  • Added support for grayscale (1-channel) images
  • Implemented handling for 2-channel images by padding to 3 channels
  • Added support for 4+ channel images by processing RGB and extra channels separately
  • Improved channel preservation for alpha and additional channels
albumentations/augmentations/functional.py
Added new RandomJPEG transform class
  • Created specialized wrapper around ImageCompression for JPEG-specific use cases
  • Added warning message to guide users to ImageCompression for more flexibility
  • Implemented pydantic schema validation for quality parameters
albumentations/augmentations/tk/transform.py
Added comprehensive test coverage for image compression
  • Added tests for different image shapes and channel counts
  • Implemented quality comparison tests to verify compression artifacts
  • Added channel consistency tests for alpha channel preservation
  • Created tests for supported image format configurations
tests/functional/test_functional.py
Updated serialization and transform definitions
  • Modified serialization test to use consistent random seeds
  • Updated transform initialization arguments handling
  • Added RandomJPEG to augmentation definitions
tests/test_serialization.py
tests/aug_definitions.py
albumentations/augmentations/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 - here's some feedback:

Overall Comments:

  • There's a duplicate test function name 'test_image_compression_quality' which should be renamed to avoid confusion
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟡 Complexity: 1 issue found
  • 🟢 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.

albumentations/augmentations/tk/transform.py Outdated Show resolved Hide resolved
tests/functional/test_functional.py Outdated Show resolved Hide resolved
albumentations/augmentations/functional.py Show resolved Hide resolved
Copy link

codecov bot commented Nov 9, 2024

Codecov Report

Attention: Patch coverage is 97.87234% with 1 line in your changes missing coverage. Please review.

Project coverage is 90.30%. Comparing base (b1a79c2) to head (876ecfb).
Report is 259 commits behind head on main.

Files with missing lines Patch % Lines
albumentations/augmentations/functional.py 96.42% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           main    #2125       +/-   ##
=========================================
+ Coverage      0   90.30%   +90.30%     
=========================================
  Files         0       48       +48     
  Lines         0     7787     +7787     
=========================================
+ Hits          0     7032     +7032     
- Misses        0      755      +755     

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

@ternaus ternaus merged commit 2d308d1 into main Nov 9, 2024
16 checks passed
@ternaus ternaus deleted the add_random_jpeg branch November 9, 2024 00:58
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.

[Add transform] Add RandomJPEG
1 participant