CropOrPad only crops Mask
See original GitHub issueTorchIO version 0.15.0
What I did Create the following sequence of transforms:
input_H = 160
input_W = 160
input_D = 80
transforms = [
torchio.transforms.ToCanonical(),
torchio.transforms.Resample(target_spacing=(1,1,1)),
torchio.transforms.RescaleIntensity(out_min_max=(0,1),percentiles=(0.5,99.5)),
torchio.transforms.ZNormalization(),
torchio.transforms.CropOrPad(target_shape=(input_D,input_H,input_W),padding_mode='constant',padding_fill=0,mask_name='mask'),
]
transform = Compose(transforms)
dataset = ImagesDataset(subjects, transform=transform)
sample = dataset[0]
I then checked the size of one of the images in the sample
e.g. sample['t2']['data'].shape
which returns torch.Size([1, 247, 345, 346])
whereas sample['mask']['data'].shape
returns torch.Size([1, 80, 160, 160])
What I expected to happen Both the image and mask have the same size
What actually happened The sizes are different.
Possible reason In the crop and pad function (here) these lines should probably be changed
padding_params = tuple(padding.tolist()) if padding.any() else None
cropping_params = tuple(cropping.tolist()) if padding.any() else None
should be
padding_params = tuple(padding.tolist()) if padding.any() else None
cropping_params = tuple(cropping.tolist()) if cropping.any() else None
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Preprocessing - TorchIO - Read the Docs
RuntimeWarning – If a 4D image is masked with a 3D mask, the mask will be expanded along the channels (first) ... method...
Read more >Crop transforms (augmentations.crops.transforms)
Crop and pad images by pixel amounts or fractions of image sizes. Cropping removes pixels at the sides (i.e. extracts a subimage from...
Read more >Cropping image from a binary mask - python - Stack Overflow
Currently, it is only possible to plot an image with an overlay mask on the object. I want to crop the object out...
Read more >Transforms — MONAI 1.1.0 Documentation
So the crop center will only come from the valid image areas. ... Mask data must have the same spatial size as the...
Read more >tf.image.resize_with_crop_or_pad | TensorFlow v2.11.0
Crops and/or pads an image to a target width and height. ... image[:,:,0] # print first channel just for demo purposes
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ok, I will give it a look
Ah ok I’ve found out why the check is not working. The shape check is only performed when doing a center crop (e.g
_compute_center_crop_or_pad
) (here). However, the check is not performed when performing a crop on the mask’s center (e.g._compute_mask_center_crop_or_pad
)