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 RandomCrop3D and CenterCrop3D #2198

Merged
merged 2 commits into from
Dec 14, 2024
Merged

Add RandomCrop3D and CenterCrop3D #2198

merged 2 commits into from
Dec 14, 2024

Conversation

ternaus
Copy link
Collaborator

@ternaus ternaus commented Dec 14, 2024

Summary by Sourcery

Add CenterCrop3D and RandomCrop3D transforms for 3D image volumes, including validation for padding values and comprehensive tests.

New Features:

  • Introduce CenterCrop3D and RandomCrop3D transforms for 3D image volumes, allowing for center and random cropping with optional padding.

Enhancements:

  • Add validation for padding values in Pad3D to ensure non-negative integers.

Documentation:

  • Update README to include CenterCrop3D and RandomCrop3D in the list of available 3D transforms.

Tests:

  • Add tests for CenterCrop3D and RandomCrop3D to verify correct cropping and padding behavior, including shape validation and reproducibility.

Copy link
Contributor

sourcery-ai bot commented Dec 14, 2024

Reviewer's Guide by Sourcery

This PR adds two new 3D transformation classes - CenterCrop3D and RandomCrop3D - to handle cropping operations on 3D volumes. The implementation includes support for padding if needed, handling different input shapes, and maintaining consistency with existing transform interfaces.

Class diagram for new 3D transformation classes

classDiagram
    class BaseCropAndPad3D {
        +bool pad_if_needed
        +ColorType fill
        +ColorType fill_mask
        +Literal pad_position
        +apply_to_images(np.ndarray images, tuple crop_coords, dict pad_params)
        +apply_to_masks(np.ndarray masks, tuple crop_coords, dict pad_params)
    }
    class CenterCrop3D {
        +tuple size
        +get_params_dependent_on_data(dict params, dict data)
    }
    class RandomCrop3D {
        +tuple size
        +get_params_dependent_on_data(dict params, dict data)
    }
    BaseCropAndPad3D <|-- CenterCrop3D
    BaseCropAndPad3D <|-- RandomCrop3D
    note for BaseCropAndPad3D "Base class for 3D transforms that need both cropping and padding"
Loading

Class diagram for updated Pad3D class

classDiagram
    class Pad3D {
        +validate_padding(int|tuple padding)
    }
    class BasePad3D {
    }
    BasePad3D <|-- Pad3D
    note for Pad3D "Updated to include padding validation"
Loading

File-Level Changes

Change Details Files
Added new base class for 3D cropping and padding operations
  • Created BaseCropAndPad3D class that handles both cropping and padding operations
  • Implemented helper methods for random and center padding calculations
  • Added padding parameter validation and calculation logic
albumentations/augmentations/transforms3d/transforms.py
Implemented CenterCrop3D and RandomCrop3D transform classes
  • Added CenterCrop3D for center-based cropping of 3D volumes
  • Added RandomCrop3D for random cropping of 3D volumes
  • Implemented padding support with configurable fill values
  • Added validation for crop size parameters
albumentations/augmentations/transforms3d/transforms.py
Added functional cropping operation for 3D volumes
  • Implemented crop function to handle 3D volume cropping
  • Added support for both 3D and 4D input arrays (with channels)
albumentations/augmentations/transforms3d/functional.py
Added comprehensive test coverage for new transforms
  • Added tests for different input shapes and dimensions
  • Added tests for padding behavior and fill values
  • Added reproducibility tests for random operations
  • Updated existing test infrastructure to include new transforms
tests/transforms3d/test_transforms.py
tests/test_core.py
tests/transforms3d/test_targets.py
tests/test_serialization.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: 1 issue found
  • 🟢 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/transforms3d/test_transforms.py Show resolved Hide resolved
tests/transforms3d/test_transforms.py Show resolved Hide resolved
tests/transforms3d/test_transforms.py Show resolved Hide resolved
tests/transforms3d/test_transforms.py Show resolved Hide resolved
tests/transforms3d/test_transforms.py Show resolved Hide resolved
tests/transforms3d/test_transforms.py Show resolved Hide resolved
tests/transforms3d/test_transforms.py Show resolved Hide resolved
tests/transforms3d/test_transforms.py Show resolved Hide resolved
@ternaus ternaus merged commit eb7c9d1 into main Dec 14, 2024
14 checks passed
@ternaus ternaus deleted the add_random_crop branch December 14, 2024 03:58
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