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

Merged
merged 10 commits into from
Jan 29, 2025
Merged

Update illumination #2318

merged 10 commits into from
Jan 29, 2025

Conversation

ternaus
Copy link
Collaborator

@ternaus ternaus commented Jan 29, 2025

Summary by Sourcery

Tests:

  • Add tests for apply_illumination_pattern, apply_linear_illumination, and create_directional_gradient.

Copy link
Contributor

sourcery-ai bot commented Jan 29, 2025

Reviewer's Guide by Sourcery

This pull request introduces two new illumination augmentation functions: apply_illumination_pattern and apply_linear_illumination. The apply_illumination_pattern function applies a given illumination pattern to an image, while the apply_linear_illumination function applies a linear gradient illumination effect. The implementation includes a new create_directional_gradient function to generate the gradient patterns. Additionally, several new tests were added to ensure the correctness of the new functions.

Sequence diagram for linear illumination application

sequenceDiagram
    participant Client
    participant LinearIllumination as apply_linear_illumination
    participant Gradient as create_directional_gradient
    participant CoreOps as albucore

    Client->>LinearIllumination: apply_linear_illumination(img, intensity, angle)
    LinearIllumination->>Gradient: create_directional_gradient(height, width, angle)
    Gradient-->>LinearIllumination: gradient pattern
    Note over LinearIllumination: Process gradient based on intensity
    LinearIllumination->>CoreOps: multiply_by_array(img, gradient)
    CoreOps-->>LinearIllumination: modified image
    LinearIllumination-->>Client: illuminated image
Loading

Class diagram for illumination functions

classDiagram
    class apply_illumination_pattern {
        +apply(img: ndarray, pattern: ndarray, intensity: float) ndarray
    }

    class apply_linear_illumination {
        +apply(img: ndarray, intensity: float, angle: float) ndarray
    }

    class create_directional_gradient {
        +create(height: int, width: int, angle: float) ndarray
    }

    apply_linear_illumination ..> create_directional_gradient : uses
    apply_linear_illumination ..> apply_illumination_pattern : replaced by

    note for apply_linear_illumination "@float32_io\n@clipped"
    note for create_directional_gradient "Optimized implementation\nwith fast paths"
Loading

File-Level Changes

Change Details Files
Added apply_illumination_pattern function to apply a given illumination pattern to an image.
  • Implemented the apply_illumination_pattern function.
  • Modified the function to use cv2.merge to handle multi-channel images.
  • Modified the function to use multiply function.
albumentations/augmentations/functional.py
Added apply_linear_illumination function to apply a linear gradient illumination effect.
  • Implemented the apply_linear_illumination function.
  • Implemented the create_directional_gradient function to generate gradient patterns.
  • Modified the function to use cv2.multiply and cv2.add for in-place operations.
  • Modified the function to use albucore.multiply_by_array function.
  • Added fast paths for common angles in create_directional_gradient function.
  • Added a general case for arbitrary angles in create_directional_gradient function.
  • Modified the function to use cv2.normalize for diagonal gradients.
albumentations/augmentations/functional.py
Added tests for the new illumination functions.
  • Added tests for apply_illumination_pattern with different image types, shapes, and intensities.
  • Added tests for apply_linear_illumination with different image types, shapes, intensities and angles.
  • Added tests to ensure that the input arrays are not modified by the functions.
  • Added tests to ensure that the functions preserve the valid range of values.
  • Added tests to ensure that opposite angles produce inverse effects.
  • Added tests for create_directional_gradient with different angles and shapes.
  • Added tests to ensure that gradient values are always in [0, 1] range.
tests/functional/test_functional.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. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the 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 exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

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: 3 issues 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.

tests/functional/test_functional.py Show resolved Hide resolved
tests/functional/test_functional.py Show resolved Hide resolved
tests/functional/test_functional.py Show resolved Hide resolved
albumentations/augmentations/functional.py Show resolved Hide resolved
tests/functional/test_functional.py Show resolved Hide resolved
tests/functional/test_functional.py Show resolved Hide resolved
tests/functional/test_functional.py Show resolved Hide resolved
albumentations/augmentations/functional.py Show resolved Hide resolved
@ternaus ternaus merged commit 057f480 into main Jan 29, 2025
14 checks passed
@ternaus ternaus deleted the update_illumination branch January 29, 2025 23:59
@ternaus ternaus restored the update_illumination branch January 30, 2025 00:40
@ternaus ternaus deleted the update_illumination branch January 30, 2025 00:40
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