-
Hi, We are trying to do random crop using Transforms like RandSpatialCropSamplesd, RandCropByPosNegLabeld on both MRI images and segmentation mask. However, after cropping is done, we would like to check if the segmentation mask has any pixels with non-zero value and if it does, we want to set label=1 otherwise label=0 for the classification. I am not clear how can I achieve this so that classifier label gets generated for each generated random cropped image and passed to the DataLoader. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
How about: def set_class(data):
data["label"] = np.any(data["segmentation"] != 0)
return data
transformations = Compose([
...,
RandCropByPosNegLabeld(...),
Lambda(set_class),
...
]) The output of |
Beta Was this translation helpful? Give feedback.
How about:
The output of
RandSpatialCropSamplesd
andRandCropByPosNegLabeld
might be lists, in which case, you'd have to put a for loop inside theset_class
function.