-
Notifications
You must be signed in to change notification settings - Fork 2k
Fixed a bug in preprocessing in crop_to_nonzero. #2796 #2824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Fixed a bug in preprocessing in crop_to_nonzero. #2796 #2824
Conversation
Hi there, thanks for the comprehensive writeup. I believe however that there are some thins you did not interpret quite right, leading to the perception there is a bug or unintended behavior. I have already written a short response outlining the need for the nonzero mask in the issue you link to, here is a rundown for why none of the suggestions are quite fitting:
Since you seem to have gone quite deep into the cropping and normalization rabbit hole may I ask whether you have encountered any issues arising from it? I would be very interested in that! PS: also remember that the -1 mask is basically never used unless cropping to nonzero region resulted in a substantial reduction in image size in which case it is used to apply normalization in a masked way |
Hi!
#2796
I’ve identified the root cause of the issue. In
preprocessing.preprocessors.default_preprocessor
, the functioncrop_to_nonzero
is called to generate anonzero_mask
of the image and crop to the region of interest—but that region is defined as every non-zero pixel in the image. Clearly, that’s not correct: any voxel inside the patient can be non-zero, and manufacturer-specific differences in CT scanner background intensity mean the background is almost never exactly zero.I see several possible solutions:
Swap the preprocessing steps: run
normalize
first, thencrop_to_nonzero
. However, this has drawbacks: if users have already cropped tightly around an organ or body region, the mask may over-crop and break training. Moreover, the CT normalization used doesn’t zero out voxels outside the body, which could lead to label errors (for example, mask labels becoming –1).Remove this heuristic entirely and let users define the ROI before preprocessing. This would increase training time, but I believe avoiding hard-to-detect errors is worth it. I suggest this option.
Add a toggle parameter to enable or disable cropping. But this approach will always perform worse than other options and require extra tuning, since background intensities vary so widely. A better idea is to leverage your body-localization model [Foreground-and-Anonymization-Area-Segmentation](https://github.com/MIC-DKFZ/Foreground-and-Anonymization-Area-Segmentation). The downsides are needing to download additional weights and perform an extra inference step, plus a small chance of failure on unusual anatomies. In my opinion, though, it’s far more robust than any simple algorithmic ROI heuristic.
I spent considerable time developing heuristics to separate patient body from background, but they invariably fail when applied to diverse data from different hospitals and scanners (on the order of 1,000–2,000 varied samples). In my experience, there’s no reliable algorithmic solution for this - it simply didn’t work for me.
I understand that at the moment this doesn’t cause major training errors—since the training pipeline applies an augmentation that replaces label values of –1 with 0—but it could potentially lead to errors if mask values, rather than background, get replaced.