ITK
ITK copied to clipboard
NiftiImageIO: incorrect reading of 4D image when fourth dimension has size one
Initial bug report and some discussion on the SimpleITK issue tracker.
The nifti reader does not read 4D images correctly when the 4'th dimension size is one. Instead of returning a 4D image a 3D image is returned. Based on the code it is intentional behavior.
Is it possible to revert to the commented out line? This "fix" was added to address a problem that should have been resolved at the application level and not the toolkit level. Unfortunately, it has been there for years, so changing behavior may break old code. Old code can be fixed at the application level (ExtractImageFilter). The current behavior does not allow one to address the issue at the application level as the knowledge whether the file contains a 4D or 3D image is lost during reading.
Opening a new PR to uncomment that sounds reasonable to me.
I would like to add something that might reveal the motivation for this choice. The official NIfTI spec states the following:
In NIFTI-1 files, dimensions 1,2,3 are for space, dimension 4 is for time, and dimension 5 is for storing multiple values at each spatiotemporal voxel.
Unfortunately, it has been there for years, so changing behavior may break old code.
This sounds like it might affect my app.
Where is there such a nifti file that I could try?
@seanm, I guess @nicktasios has a real image but here's a toy one:
import SimpleITK as sitk
image = sitk.Image([64,64,64,1], sitk.sitkFloat32)
sitk.WriteImage(image, 'temp.nii.gz')