I would like to take a 3D segmentation (nifti) and then create a new 4D nifti where the 4th dimension has has split up the label image where each element is the 3D image with just one label in each of them - is there an obvious way to do this?
The end goal would be to perform transformations on each of the labels and stitch it back together.
any help (or pointing to examples) would be great!
It would be great if the NearestNeighborInterpolateImageFunction was the option, but unfortunately Nearest neighbour Interpolants are quite lossy. In my research - what has worked better was a splitting of the labels and performing specialised transforms for each. I’ve tried ITK’s nearest neighbour implementation in python and its no better than other algorithms unfortunately.
So this is why I would like to create a 4D image, so any help would be great!
FYI: Performing my specialised transforms in python work well but It takes close to 30s and I would prefer to speed this up directly in C++.
For a few years we switched to representing segmentations using such 4D volumes but we reverted to using 3D volumes (except for storing overlapping segments) because of increased memory requirement and incompatibility with processing algorithms. So, I would not recommend to switch to this representation just to improve segmentation quality. Instead, you can keep a 3D labelmap and increase its resolution as needed.
If you just temporarily want to split the segmentation to separate volumes then it is very easy to do, for example using threshold filter.
Nearest neighbor interpolation is not optimal, especially when the target resolution is higher. You can use these readily available approaches for labelmap interpolation or you can port your slow Python code to C++ and add Python wrapping for it (for example, make an ITK filter from it and add it as an ITK remote module).
For me, a segmentation, label map, Python numpy array are almost the same. The only difference is how you store extra metadata - at the minimum, image geometry (origin, spacing, and axis directions), but preferably also segment names, standard terminology, and other optional attributes.
ITK can already preserve image geometry using xarray. I don’t think there is a common standard for storing additional segmentation metadata in xarrays, but maybe it will come out as a side product of the OME-Zarr - next-generation biomedical file format effort.