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

padding and cropping classes use MetaTensor #4371

Merged
merged 48 commits into from
Jun 6, 2022

Conversation

rijobro
Copy link
Contributor

@rijobro rijobro commented May 27, 2022

Description

Pad transforms use MetaTensor to allow inverse.

also fixes #4435

Status

Ready

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • Breaking change (fix or new feature that would cause existing functionality to change).
  • New tests added to cover the changes.

TODO

Name Array implementation Dict implementation Array test Dict test
SpatialPad ✔️ ✔️ ✔️ ✔️
BorderPad ✔️ ✔️ ✔️ ✔️
DivisiblePad ✔️ ✔️ ✔️ ✔️
SpatialCrop ✔️ ✔️ ✔️ ✔️
CenterSpatialCrop ✔️ ✔️ ✔️ ✔️
CenterScaleCrop ✔️ ✔️ ✔️ ✔️
RandSpatialCrop ✔️ ✔️ ✔️ ✔️
RandScaleCrop ✔️ ✔️ ✔️ ✔️
RandSpatialCropSamples ✔️ ✔️ ✔️ ✔️
CropForeground ✔️ ✔️ ✔️ ✔️
RandWeightedCrop ✔️ ✔️ ✔️ ✔️
RandCropByPosNegLabel ✔️ ✔️ ✔️ ✔️
RandCropByLabelClasses ✔️ ✔️ ✔️ ✔️
ResizeWithPadOrCop ✔️ ✔️ ✔️ ✔️

@rijobro rijobro requested review from wyli, ericspod and Nic-Ma May 27, 2022 14:24
@wyli
Copy link
Contributor

wyli commented May 31, 2022

/black

monai-bot and others added 3 commits May 31, 2022 12:41
@wyli wyli force-pushed the MetaTensor_pad branch from 034869f to 7fd4836 Compare May 31, 2022 13:39
@rijobro
Copy link
Contributor Author

rijobro commented May 31, 2022

@wyli PR is getting very big as I'm doing all padding and cropping. Apologies for that, it's a hard one to split.

@rijobro rijobro marked this pull request as draft May 31, 2022 16:43
Signed-off-by: Richard Brown <[email protected]>
@rijobro rijobro changed the title padding classes use MetaTensor for inverse padding and cropping classes use MetaTensor Jun 1, 2022
@rijobro
Copy link
Contributor Author

rijobro commented Jun 1, 2022

@wyli Could you create unit tests for the _forward_meta methods? I added test_meta_update to test_pad.py (link). I wanted to check that for out = padder(im), the input metadata was unchanged, and out had been updated. I see that the output affine is only 2x2. Could you check this? Putting the same check for cropping would be good too.

Equally we would want to check that the affine isn't modified when we don't crop/pad from the origin.

@wyli
Copy link
Contributor

wyli commented Jun 1, 2022

@wyli Could you create unit tests for the _forward_meta methods?

sure let me add some basic tests to this PR now...

rijobro and others added 2 commits June 1, 2022 11:52
Signed-off-by: Richard Brown <[email protected]>
adds meta tests pad/crop

Signed-off-by: Wenqi Li <[email protected]>
@wyli wyli force-pushed the MetaTensor_pad branch from 432573b to 89ed8c1 Compare June 1, 2022 11:14
tests/test_pad.py Outdated Show resolved Hide resolved
Signed-off-by: Richard Brown <[email protected]>
@rijobro
Copy link
Contributor Author

rijobro commented Jun 1, 2022

@wyli thanks for the help here. I'm off for a week, feel free to continue this without me if you want to. All transforms have been updated, just need to get all the linting happy. I suspect #4435 will need to be addressed first.

@wyli
Copy link
Contributor

wyli commented Jun 1, 2022

@wyli thanks for the help here. I'm off for a week, feel free to continue this without me if you want to. All transforms have been updated, just need to get all the linting happy. I suspect #4435 will need to be addressed first.

thanks! I'll try to merge this one soon.

@wyli wyli force-pushed the MetaTensor_pad branch from 46c1a15 to 180fefd Compare June 6, 2022 12:54
@wyli wyli force-pushed the MetaTensor_pad branch from 180fefd to 9a92b26 Compare June 6, 2022 13:01
Signed-off-by: Wenqi Li <[email protected]>
@wyli wyli marked this pull request as ready for review June 6, 2022 15:09
@wyli
Copy link
Contributor

wyli commented Jun 6, 2022

cropping with multiple random samples (basic applied_operations collating/decollating work fine)

from monai.transforms import EnsureChannelFirst, LoadImage, RandSpatialCropSamples, SaveImage

filename = "~/Downloads/avg152T1_LR_nifti.nii.gz"
img = LoadImage()(filename)
img = EnsureChannelFirst()(img)
img = RandSpatialCropSamples(roi_size=(40, 50, 60), random_size=False, num_samples=3)(img)
for i in img:
    SaveImage(resample=False)(i)

Screenshot 2022-06-06 at 16 23 58

Copy link
Contributor

@wyli wyli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging this for now as the basic functionality works nicely, but it will need another discussion/refactoring for the design of modules such as the PadBase class

class PadBase(InvertibleTransform):
cc @Nic-Ma @ericspod

@wyli wyli merged commit 04e5a14 into Project-MONAI:feature/MetaTensor Jun 6, 2022
@wyli wyli mentioned this pull request Jun 6, 2022
12 tasks
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.

3 participants