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:
- Segment the “background” (BG) pixels
- Compute a bounding box (BB) for the not BG, where a BB is axis aligned and ONLY contains non-BG pixel?
- 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.
If you are using SimpleITK, then this Jupyter notebook has a function that does what you want,
SimpleITK/ITK provide several standard thresholding methods:
OtsuThresholdImageFilter, TriangleThresholdImageFilter, HuangThresholdImageFilter, MaximumEntropyThresholdImageFilter.