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

Fix #2286

Merged
merged 1 commit into from
Jan 22, 2025
Merged

Fix #2286

merged 1 commit into from
Jan 22, 2025

Conversation

ternaus
Copy link
Collaborator

@ternaus ternaus commented Jan 22, 2025

Fixes: #2285

Summary by Sourcery

Fix keypoint remapping and bounding box remapping logic, and update Codespell.

Bug Fixes:

  • Fix bounding box and keypoint remapping for edge cases.

Tests:

  • Add tests for bounding box to mask conversion and vice-versa.

Copy link
Contributor

sourcery-ai bot commented Jan 22, 2025

Reviewer's Guide by Sourcery

This pull request introduces a new implementation for remapping bounding boxes using masks. It also includes new tests for the mask to bounding box conversion and fixes a bug in the camera and fisheye distortion transforms.

Sequence diagram for the new bounding box remapping process

sequenceDiagram
    participant C as Client
    participant R as Remapper
    participant M as MaskConverter

C->>R: remap_bboxes(bboxes, map_x, map_y)
R->>M: bboxes_to_mask(bboxes)
Note right of M: Convert bboxes to multi-channel mask
M-->>R: bbox_masks
R->>R: remap(bbox_masks)
Note right of R: Apply displacement maps
R->>M: mask_to_bboxes(transformed_masks)
Note right of M: Convert masks back to bboxes
M-->>R: new_bboxes
R-->>C: transformed bboxes
Loading

Class diagram for the updated bbox utils

classDiagram
    class BBoxUtils {
        +bboxes_to_mask(bboxes: ndarray, image_shape: tuple) ndarray
        +mask_to_bboxes(masks: ndarray, original_bboxes: ndarray) ndarray
        +masks_from_bboxes(bboxes: ndarray, shape: tuple) ndarray
    }
    note for BBoxUtils "New mask-based bbox transformation methods"

    class GeometricFunctional {
        +remap_bboxes(bboxes: ndarray, map_x: ndarray, map_y: ndarray, image_shape: tuple) ndarray
        +get_camera_matrix_distortion_maps(image_shape: tuple, k: float) tuple
        +get_fisheye_distortion_maps(image_shape: tuple, k: float) tuple
    }
    note for GeometricFunctional "Simplified distortion methods"
Loading

Flow diagram for bbox remapping process

flowchart TD
    A[Input Bboxes] --> B[Convert to Mask]
    B --> C[Apply Displacement Maps]
    C --> D[Convert Back to Bboxes]
    D --> E[Output Transformed Bboxes]

    subgraph Mask Processing
    B
    C
    D
    end

    note[New mask-based approach replaces<br>the old point-sampling method]
Loading

File-Level Changes

Change Details Files
Added functions to convert bounding boxes to masks and vice versa.
  • Added bboxes_to_mask function to convert bounding boxes to a multi-channel binary mask.
  • Added mask_to_bboxes function to convert a multi-channel binary mask back to bounding boxes.
albumentations/core/bbox_utils.py
Implemented bounding box remapping using masks.
  • Modified remap_bboxes function to use bboxes_to_mask and mask_to_bboxes for remapping.
  • Removed the grid sampling approach for remapping bounding boxes.
  • Ensured that the displacement maps are of type float32 before remapping.
albumentations/augmentations/geometric/functional.py
Fixed a bug in the camera and fisheye distortion transforms.
  • Removed the center_xy parameter from get_camera_matrix_distortion_maps and get_fisheye_distortion_maps functions.
  • Calculated the center of the image directly within the get_camera_matrix_distortion_maps and get_fisheye_distortion_maps functions.
  • Removed the center_xy parameter from the get_camera_matrix_distortion_maps and get_fisheye_distortion_maps calls in get_params_dependent_on_data.
albumentations/augmentations/geometric/functional.py
albumentations/augmentations/geometric/transforms.py
Added new tests for mask to bounding box conversion.
  • Added new test cases for bboxes_to_mask function.
  • Added new test cases for mask_to_bboxes function.
  • Added a test case for empty bounding boxes.
tests/test_bbox.py
Updated codespell version.
  • Updated codespell version from v2.3.0 to v2.4.0.
.pre-commit-config.yaml

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: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 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/test_bbox.py Show resolved Hide resolved
tests/test_bbox.py Show resolved Hide resolved
Copy link

codecov bot commented Jan 22, 2025

Codecov Report

Attention: Patch coverage is 97.91667% with 1 line in your changes missing coverage. Please review.

Project coverage is 89.87%. Comparing base (b1a79c2) to head (5a92b64).
Report is 385 commits behind head on main.

Files with missing lines Patch % Lines
...bumentations/augmentations/geometric/functional.py 94.73% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           main    #2286       +/-   ##
=========================================
+ Coverage      0   89.87%   +89.87%     
=========================================
  Files         0       50       +50     
  Lines         0     8838     +8838     
=========================================
+ Hits          0     7943     +7943     
- Misses        0      895      +895     
Flag Coverage Δ
ubuntu-py3.12 89.87% <97.91%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@ternaus ternaus merged commit 107c4ba into main Jan 22, 2025
16 checks passed
@ternaus ternaus deleted the fix_in_optical_distortion branch January 22, 2025 21:08
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.

Error in keypoints when using large optical distortions
1 participant