Writing a bunch of 3D Images (Nifti Format) into one whole 4D Image.

Do you want to write segmentation that contains overlapping segments into a NIFTI file? As far as I know, no such convention exists for this format. Due to rigidity of NIFTI file header, it would not be possible to create a standard NIFTI file that contains metadata describing how to properly interpret you 4D volume.

In contrast, NRRD files (with 3D Slicer’s segmentation metadata convention) has been used widely for this purpose for a long time. This format can use a single shared 3D volume between non-overlapping segments, so most segmentations fit in a few 3D volumes in the 4D file. For example, if you have 300 non-overlapping brain structures segmented and you define an additional region that overlaps with some of those structures, then you don’t need to store 301 but only 2 volumes in the 4D file. This file format can also store standard coded terms to specify the meaning of each segment. You can find the file specification here. You can read/write segments in Python using slicerio package. There is also a topic about how to create such files using ITK.

4 Likes