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

Refactor affine #2008

Merged
merged 8 commits into from
Oct 23, 2024
Merged

Refactor affine #2008

merged 8 commits into from
Oct 23, 2024

Conversation

ternaus
Copy link
Collaborator

@ternaus ternaus commented Oct 22, 2024

Summary by Sourcery

Refactor affine transformation functions to use numpy arrays for matrix operations, replacing skimage dependencies. Enhance test coverage for affine transformations, including translation, scaling, rotation, shear, and combined transformations, to ensure correctness and robustness.

Enhancements:

  • Refactor affine transformation functions to use numpy arrays instead of skimage for matrix operations, improving performance and reducing dependencies.

Tests:

  • Add comprehensive tests for affine transformations, including translation, scaling, rotation, shear, and combined transformations, to ensure correctness and robustness.

Copy link
Contributor

sourcery-ai bot commented Oct 22, 2024

Reviewer's Guide by Sourcery

This pull request refactors the affine transformation functionality in the Albumentations library. The main changes include replacing the use of skimage's ProjectiveTransform with custom numpy-based affine transformation matrices, updating the rotation and other geometric transformations to use the new affine matrix approach, and adjusting various tests to accommodate these changes.

Sequence diagram for applying affine transformation to an image

sequenceDiagram
    participant Test
    participant fgeometric
    participant cv2
    Test->>fgeometric: create_affine_transformation_matrix(...)
    fgeometric-->>Test: affine_matrix
    Test->>fgeometric: warp_affine(image, affine_matrix, ...)
    fgeometric->>cv2: cv2.warpAffine(image, affine_matrix[:2], ...)
    cv2-->>fgeometric: transformed_image
    fgeometric-->>Test: transformed_image
Loading

Class diagram for updated affine transformation functions

classDiagram
    class fgeometric {
        +create_affine_transformation_matrix(translate, shear, scale, rotate, shift) np.ndarray
        +warp_affine(image, matrix, interpolation, cval, mode, output_shape) np.ndarray
        +keypoints_affine(keypoints, matrix, image_shape, scale, mode) np.ndarray
        +apply_affine_to_points(points, matrix) np.ndarray
        +calculate_affine_transform_padding(matrix, image_shape) tuple[int, int, int, int]
        +bboxes_affine_largest_box(bboxes, matrix) np.ndarray
        +bboxes_affine_ellipse(bboxes, matrix) np.ndarray
    }
    note for fgeometric "Refactored to use numpy-based affine transformation matrices instead of skimage's ProjectiveTransform"
Loading

File-Level Changes

Change Details Files
Replace skimage's ProjectiveTransform with custom numpy-based affine transformation matrices
  • Implement create_affine_transformation_matrix function to generate 3x3 affine matrices
  • Update warp_affine function to use numpy arrays instead of ProjectiveTransform objects
  • Modify keypoints_affine, bboxes_affine, and other related functions to work with numpy matrices
albumentations/augmentations/geometric/functional.py
albumentations/augmentations/geometric/rotate.py
albumentations/augmentations/geometric/transforms.py
Refactor rotation and other geometric transformations to use the new affine matrix approach
  • Update Rotate class to use affine matrices for transformations
  • Modify SafeRotate class to work with the new affine matrix system
  • Adjust Affine class to use the new create_affine_transformation_matrix function
albumentations/augmentations/geometric/rotate.py
albumentations/augmentations/geometric/transforms.py
Update and add tests to accommodate the new affine transformation approach
  • Modify existing tests to work with the new affine matrix system
  • Add new tests for the create_affine_transformation_matrix function
  • Update rotation tests to use the new affine approach
tests/test_transforms.py
tests/test_functional.py
tests/test_keypoint.py
Remove deprecated or redundant functions and tests
  • Remove rotate function and related tests
  • Delete bboxes_rotate and keypoints_rotate functions
  • Remove test_compare_rotate_and_affine and other obsolete tests
albumentations/augmentations/geometric/functional.py
tests/test_functional.py
tests/test_keypoint.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:

  • This refactoring of the affine transformation functionality looks like a solid improvement. The shift from skimage's ProjectiveTransform to NumPy arrays should enhance performance and reduce dependencies. However, given the extent of the changes, we recommend thorough testing with real-world use cases to ensure no regressions have been introduced.
  • The removal of the rotate() function and consolidation into the general affine transformation framework may impact the API. Please ensure any API changes or deprecations are clearly documented and communicated to users.
  • The additional test cases and attention to numerical stability are commendable. Consider adding more tests that cover a wide range of inputs and edge cases to verify the robustness of the new implementation.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟢 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.

tests/functional/test_affine.py Outdated Show resolved Hide resolved
tests/functional/test_affine.py Show resolved Hide resolved
tests/functional/test_affine.py Show resolved Hide resolved
tests/functional/test_affine.py Show resolved Hide resolved
tests/functional/test_affine.py Show resolved Hide resolved
tests/functional/test_affine.py Show resolved Hide resolved
tests/functional/test_affine.py Show resolved Hide resolved
tests/functional/test_affine.py Show resolved Hide resolved
tests/functional/test_affine.py Show resolved Hide resolved
tests/functional/test_affine.py Show resolved Hide resolved
@ternaus ternaus merged commit 153781f into main Oct 23, 2024
14 checks passed
@ternaus ternaus deleted the refactor_affine branch October 23, 2024 00:11
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