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 illumination #2155

Merged
merged 4 commits into from
Nov 19, 2024
Merged

Add illumination #2155

merged 4 commits into from
Nov 19, 2024

Conversation

ternaus
Copy link
Collaborator

@ternaus ternaus commented Nov 19, 2024

Summary by Sourcery

Add a new Illumination transform to the library, allowing users to simulate various lighting conditions on images. Update the README to include documentation for this new feature and add corresponding tests to validate its implementation.

New Features:

  • Introduce the Illumination transform to apply various illumination effects to images, simulating different lighting conditions such as directional lighting, corner shadows, and spotlights.

Documentation:

  • Add documentation for the new Illumination transform in the README, including a link to its detailed description.

Tests:

  • Add test definitions for the new Illumination transform to ensure its functionality.

Copy link
Contributor

sourcery-ai bot commented Nov 19, 2024

Reviewer's Guide by Sourcery

This PR introduces a new image augmentation transform called 'Illumination' that simulates various lighting effects. The implementation includes three different illumination modes (linear, corner, and gaussian) with configurable parameters for intensity, angle, position, and effect type. The transform is integrated into the albumentations library with proper documentation, type hints, and test coverage.

Class diagram for the new Illumination transform

classDiagram
    class Illumination {
        +Illumination(mode: Literal["linear", "corner", "gaussian"] = "linear", intensity_range: tuple[float, float] = (0.01, 0.2), effect_type: Literal["brighten", "darken", "both"] = "both", angle_range: tuple[float, float] = (0, 360), center_range: tuple[float, float] = (0.1, 0.9), sigma_range: tuple[float, float] = (0.2, 1.0), always_apply: bool = False, p: float = 0.5)
        +get_params() dict[str, Any]
        +apply(img: np.ndarray, **params: Any) np.ndarray
        +get_transform_init_args_names() tuple[str, ...]
    }
    class BaseTransformInitSchema {
    }
    Illumination --|> ImageOnlyTransform
    Illumination : +mode
    Illumination : +intensity_range
    Illumination : +effect_type
    Illumination : +angle_range
    Illumination : +center_range
    Illumination : +sigma_range
    Illumination : +p
    Illumination : +InitSchema
    class InitSchema {
        +mode: Literal["linear", "corner", "gaussian"]
        +intensity_range: Annotated[tuple[float, float], AfterValidator]
        +effect_type: Literal["brighten", "darken", "both"]
        +angle_range: Annotated[tuple[float, float], AfterValidator]
        +center_range: Annotated[tuple[float, float], AfterValidator]
        +sigma_range: Annotated[tuple[float, float], AfterValidator]
    }
    InitSchema --|> BaseTransformInitSchema
    note for Illumination "This class simulates various lighting effects on images."
Loading

Class diagram for the new functional methods

classDiagram
    class Functional {
        +apply_linear_illumination(img: np.ndarray, intensity: float, angle: float) np.ndarray
        +apply_corner_illumination(img: np.ndarray, intensity: float, corner: int) np.ndarray
        +apply_gaussian_illumination(img: np.ndarray, intensity: float, center: tuple[float, float], sigma: float) np.ndarray
    }
    note for Functional "These methods apply different illumination effects to images."
Loading

File-Level Changes

Change Details Files
Added new Illumination transform class with comprehensive configuration options
  • Implemented three illumination modes: linear (directional lighting), corner (corner shadows/highlights), and gaussian (spotlights)
  • Added configurable parameters for intensity, effect type (brighten/darken), angle range, center position, and sigma
  • Included detailed documentation with examples and references
  • Added type validation using InitSchema
albumentations/augmentations/transforms.py
Implemented core illumination effect functions
  • Created apply_linear_illumination for directional gradient effects
  • Added apply_corner_illumination for corner-based lighting
  • Implemented apply_gaussian_illumination for spotlight effects
  • Added clipping decorator to ensure proper image value ranges
albumentations/augmentations/functional.py
Updated project documentation and test configuration
  • Added Illumination to the list of available transforms in README.md
  • Included Illumination in the test definitions
README.md
tests/aug_definitions.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 found some issues that need to be addressed.

Blocking issues:

  • Missing dedicated test file for the new Illumination transform (link)
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🔴 Testing: 1 blocking issue
  • 🟡 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/functional.py Show resolved Hide resolved
tests/aug_definitions.py Show resolved Hide resolved
albumentations/augmentations/functional.py Outdated Show resolved Hide resolved
Copy link

codecov bot commented Nov 19, 2024

Codecov Report

Attention: Patch coverage is 62.19512% with 31 lines in your changes missing coverage. Please review.

Project coverage is 90.04%. Comparing base (b1a79c2) to head (ea19449).
Report is 287 commits behind head on main.

Files with missing lines Patch % Lines
albumentations/augmentations/functional.py 52.50% 19 Missing ⚠️
albumentations/augmentations/transforms.py 71.42% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           main    #2155       +/-   ##
=========================================
+ Coverage      0   90.04%   +90.04%     
=========================================
  Files         0       48       +48     
  Lines         0     8481     +8481     
=========================================
+ Hits          0     7637     +7637     
- Misses        0      844      +844     

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


🚨 Try these New Features:

@ternaus ternaus merged commit c3059b3 into main Nov 19, 2024
16 checks passed
@ternaus ternaus deleted the add_illumination branch November 19, 2024 00:39
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