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 thin plate spline #2156

Merged
merged 3 commits into from
Nov 19, 2024
Merged

Add thin plate spline #2156

merged 3 commits into from
Nov 19, 2024

Conversation

ternaus
Copy link
Collaborator

@ternaus ternaus commented Nov 19, 2024

Summary by Sourcery

Add the Thin Plate Spline transformation to the library, enabling smooth, non-rigid deformations of images and other targets. Update documentation and tests to include this new feature.

New Features:

  • Introduce the Thin Plate Spline (TPS) transformation to apply smooth, non-rigid deformations to images, masks, keypoints, and bounding boxes.

Enhancements:

  • Refactor the initialization order of parameters in the BaseDistortion class to improve code readability.

Documentation:

  • Add documentation for the new Thin Plate Spline transformation, including usage examples and references.

Tests:

  • Add a test case for the Thin Plate Spline transformation in the augmentation definitions.

Copy link
Contributor

sourcery-ai bot commented Nov 19, 2024

Reviewer's Guide by Sourcery

This PR introduces a new Thin Plate Spline (TPS) transformation for creating smooth, non-rigid deformations in images. The implementation includes the core TPS algorithm with control points and interpolation, built on top of the existing BaseDistortion class. The transform allows for configurable deformation strength and control point density while maintaining image continuity.

Class diagram for ThinPlateSpline transformation

classDiagram
    class BaseDistortion {
        <<abstract>>
        +interpolation: int
        +border_mode: int
        +value: ColorType | None
        +mask_value: ColorType | None
        +p: float
        +get_params_dependent_on_data(params: dict[str, Any], data: dict[str, Any]) dict[str, Any]
        +get_transform_init_args_names() tuple[str, ...]
    }
    class ThinPlateSpline {
        +scale_range: tuple[float, float]
        +num_control_points: int
        +interpolation: int
        +mask_interpolation: int
        +border_mode: int
        +value: ColorType | None
        +mask_value: ColorType | None
        +p: float
        +get_params_dependent_on_data(params: dict[str, Any], data: dict[str, Any]) dict[str, Any]
        +get_transform_init_args_names() tuple[str, ...]
    }
    BaseDistortion <|-- ThinPlateSpline
    class InitSchema {
        +scale_range: tuple[float, float]
        +num_control_points: int
    }
    ThinPlateSpline --> InitSchema
    note for ThinPlateSpline "Applies TPS transformation for smooth, non-rigid deformations."
Loading

Class diagram for TPS functional methods

classDiagram
    class Functional {
        +compute_tps_weights(src_points: np.ndarray, dst_points: np.ndarray) tuple[np.ndarray, np.ndarray]
        +tps_transform(target_points: np.ndarray, control_points: np.ndarray, nonlinear_weights: np.ndarray, affine_weights: np.ndarray) np.ndarray
    }
    note for Functional "Contains core TPS algorithm methods."
Loading

File-Level Changes

Change Details Files
Implementation of the Thin Plate Spline (TPS) transformation class
  • Added new ThinPlateSpline class inheriting from BaseDistortion
  • Implemented initialization with configurable scale range and control points
  • Added parameter validation through InitSchema
  • Created data-dependent parameter generation for TPS transformation
  • Added comprehensive documentation with usage examples and references
albumentations/augmentations/geometric/transforms.py
Added core TPS mathematical functions
  • Implemented compute_tps_weights function for calculating transformation weights
  • Added tps_transform function for applying the transformation to points
  • Included detailed mathematical computations for kernel matrices and affine transformations
albumentations/augmentations/geometric/functional.py
Integration with the library's infrastructure
  • Added ThinPlateSpline to the list of available transforms
  • Updated documentation table with TPS transform compatibility
  • Added TPS to the test definitions
README.md
tests/aug_definitions.py
albumentations/augmentations/geometric/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 and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 2 issues 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/geometric/functional.py Outdated Show resolved Hide resolved
tests/aug_definitions.py Show resolved Hide resolved
Copy link

codecov bot commented Nov 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.12%. Comparing base (b1a79c2) to head (01dc1b0).
Report is 288 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##           main    #2156       +/-   ##
=========================================
+ Coverage      0   90.12%   +90.12%     
=========================================
  Files         0       48       +48     
  Lines         0     8530     +8530     
=========================================
+ Hits          0     7688     +7688     
- Misses        0      842      +842     

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


🚨 Try these New Features:

@ternaus ternaus merged commit 0eeadbf into main Nov 19, 2024
16 checks passed
@ternaus ternaus deleted the add_thin_plate_spline branch November 19, 2024 01:54
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