I am working on a MONAI-based whole head segmentation tool, which predicts close to 30 tissue labels.
Currently all post-processing is implemented in Python using SimpleITK. Once we have done some clean-up operations at 1mm resolution, we need to insert thin layers of Dura and Cerebrospinal fluid. For this purpose we resample the segmentation to 0.3-0.5mm using the ResampleImageFilter (sitkLabelGaussian option).
Unfortunately, this gets very slow (it is using all CPUs). Is there any way to get smooth interpolation (i.e. not nearest neighbor) but better performance. I doubt computing the signed distance transform and smoothing for each label will scale nicely (approx. 30 labels).
convert labels to one-hot (e.g. 10 channels for labels in range [0, 9]).
smooth the one-hot “vector” image
resample the smoothed on-hot image
perform argmax to get resampled & smoothed labels
The problem is that this will explode memory usage (at least GPU)). For 600x600x600 images, with 30 labels, using 32-bit float we would need 24 GB (600 x 600 x 600 x 30 x 4 B) per one-hot image.
To solve the memory issue, we could maybe use 16-bit float (torch.half). A much more drastic saving would be to iterate over the channels, and update the current maximum of the smooth indicator functions and corresponding label.
Note: Of course the CPU memory might be enough, but then the performance will not be better than the current sitkLabelGaussian.
The above may more efficiently be implemented in SimpleITK/ITK using the LabelMap representation. The LabelMap “Images” a represented as sparse RLE. Each label could be extracted the smoothing/resampling performed and then converted to a LabelMap and merged together.
Alternatively consider using morphological operations to smooth the results after nearest neighbor interpolation? Performing opening and closing may yield acceptable results.
There is a ITK remove module ITKLabelErodeDilate which efficiently operates on multi-labeled images. I demoed it once a while ago, but have not used it recently.
The author of the module @richard.beare who may have more information on if its suitable for this application.
Have you looked at the more general GenericLabelInterpolator where you can substitute the linear analog? The related IJ article shows evidence improvement in terms of both accuracy and computational performance over the Gaussian version that I wrote. For what it’s worth, it’s what we’ve been using in ANTs for years.
True. Thanks @ntustison! I have only used the GenericLabelInterpolator from C++ but I see could try the GenericLabelInterpolator via the python remote module.
Maybe I will create a PR to add it as sitkLabelLinear to SimpleITK.