-
-
Notifications
You must be signed in to change notification settings - Fork 11
added downsample arg to ThinPlateSpline #27
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
base: main
Are you sure you want to change the base?
added downsample arg to ThinPlateSpline #27
Conversation
Reviewer's GuideIntroduces a downsample_factor parameter to ThinPlateSpline and replaces full-resolution TPS mapping with a downsampled grid followed by interpolation to improve performance. Class diagram for ThinPlateSpline with downsample_factorclassDiagram
class ThinPlateSpline {
+interpolation
+border_mode
+value
+mask_value
+scale_range
+num_control_points
+downsample_factor
+get_params_dependent_on_data(params)
}
Flow diagram for TPS mapping with downsampling and interpolationflowchart TD
A[Start get_params_dependent_on_data] --> B[Generate src_points]
B --> C[Generate dst_points with random displacement]
C --> D[Compute TPS weights]
D --> E[Create coarse grid using downsample_factor]
E --> F[Apply TPS transform to coarse grid]
F --> G[Reshape to coarse map_x_coarse, map_y_coarse]
G --> H[Interpolate coarse maps to full resolution]
H --> I[Return map_x, map_y]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a downsample_factor
parameter to the ThinPlateSpline
augmentation, generating a coarser TPS grid and resizing it back to full resolution to improve performance.
- Introduce
downsample_factor
argument in__init__
and store it on the instance. - Compute a coarse sampling grid, apply TPS transform, then upsample via OpenCV.
- Return full-resolution
map_x
andmap_y
based on the interpolated coarse grid.
Comments suppressed due to low confidence (3)
albumentations/augmentations/geometric/distortion.py:1048
- Add input validation in the constructor to ensure
downsample_factor
is an integer >= 1, so that invalid (zero or negative) values cannot cause division-by-zero or other errors.
downsample_factor: int = 1,
albumentations/augmentations/geometric/distortion.py:1048
- Update the class and method docstrings to describe the new
downsample_factor
parameter, its valid range, and how it affects the generated TPS maps.
downsample_factor: int = 1,
albumentations/augmentations/geometric/distortion.py:1068
- Add unit tests covering cases where
downsample_factor > 1
, verifying that the coarse-to-full interpolation yields maps with the expected shape and transforms.
height, width = params["shape"][:2]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @ExtReMLapin - I've reviewed your changes - here's some feedback:
- Add validation to ensure downsample_factor is a positive integer greater than zero to prevent invalid grid computations.
- Clamp or enforce a minimum coarse grid size so that coarse_height and coarse_width never collapse to zero when downsample_factor is large relative to the image dimensions.
- Consider exposing the interpolation method used in cv2.resize (or aligning it with the existing interpolation parameter) so users can control the map upsampling behavior.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Add validation to ensure downsample_factor is a positive integer greater than zero to prevent invalid grid computations.
- Clamp or enforce a minimum coarse grid size so that coarse_height and coarse_width never collapse to zero when downsample_factor is large relative to the image dimensions.
- Consider exposing the interpolation method used in cv2.resize (or aligning it with the existing interpolation parameter) so users can control the map upsampling behavior.
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
@ExtReMLapin I do not like any licenses for open source, except permissive like MIT, Apaches, etc But I do not see any other way to support the development financially. Dual license is not the best solution, just the least worst of ones that I can think of. |
And you need to set up pre-commit hook and run it: https://github.com/albumentations-team/AlbumentationsX/blob/main/docs/contributing/environment_setup.md#4-set-up-pre-commit-hooks |
@@ -1045,6 +1045,7 @@ def __init__( | |||
] = cv2.BORDER_CONSTANT, | |||
fill: tuple[float, ...] | float = 0, | |||
fill_mask: tuple[float, ...] | float = 0, | |||
downsample_factor: int = 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You also need to add distortion_factor to InitSchema, so that it's range would be checked on init by pydantic
something like:
downsample_factor: int = Field(ge=1)
ported from albumentations-team/albumentations#2572
Summary by Sourcery
Add a
downsample_factor
option to ThinPlateSpline and update its parameter-generation logic to build a coarser deformation grid and resize it to the original image size.New Features:
downsample_factor
parameter to ThinPlateSpline augmentation to compute control grids at a lower resolution.Enhancements: