-
|
Hi, I’m currently working on a project that deals with 3D nifti (nii.gz) files: one image and one label file for each patient case. Each image and label file is composed of the same shape. I’m using “compose” from Monai to pre-process the images before performing deep learning, and I want to crop the image file to [128, 128, 128] based on the label file that indicates the targeted location. The label file consists of 1 and 0 (1 being the targeted location), and I want to find the center of the target and crop the image based on the target location. I initially tried to use “Resized” but later I realized that this code crops the image by zooming in when the targeted location is on the verge of the image (when there is not enough space to shape [128, 128, 128]). I want to add zero padding instead of zooming in to fit the image to the desired shape, so I found “center_of_mass” from scipy.ndimage. I want to use “center_of_mass” instead of “Resized”, but I’m not sure how I can use this in the below code. Please help me out if anyone has faced or seen a similar problem with me. Thank you. import torch |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Hi @jl3282, if you want to crop the image based on the label, you could simply use Hope it can help you, thanks! |
Beta Was this translation helpful? Give feedback.
Hi @jl3282, if you want to crop the image based on the label, you could simply use
CropForeground, and usemarginarg to add some margin to the crop area, then useResizeWithPadOrCropto make all images the same size. Here I give you an example.Hope it can help you, thanks!