Crop a 3D volumetric medical image

Hello ,

I have two different modality images . CT and PET whole body. For each of them I want to crop the images in x and y dimension such that the background black pixels are removed. I want to get rid of black space outside the image . I cannot find a suitable function for the 3D image .Also the image type is float32. I have tried otsu’s thresholding based cropping but I suppose that only works for uint8. Is there any function or a small example would be helpful.

I see 3 steps here:

  1. Segment the “background” (BG) pixels
  2. Compute a bounding box (BB) for the not BG, where a BB is axis aligned and ONLY contains non-BG pixel?
  3. Do the cropping based on the BB

Where specifically are you having difficulties?

The Otsu thresholding does work for float, however the default is a 255 bin histogram so if there is significant outliers the automatic range of the histogram may not produce useful results.

1 Like

Hello @DL_Begin,

If you are using SimpleITK, then this Jupyter notebook has a function that does what you want, threshold_based_crop.

SimpleITK/ITK provide several standard thresholding methods: OtsuThresholdImageFilter, TriangleThresholdImageFilter, HuangThresholdImageFilter, MaximumEntropyThresholdImageFilter.