The vtkNIFTIImageReader will read all of the volumes that are stored in the file. The output of the reader will be a multi-component vtkImageData. By multi-component, I mean that each voxel will have N components, where N is the vector dimentions (the dim[5] value stored in the header).
If you have a way of dumping the header contents for your file, that would be very useful for figuring out exactly how they are structured. For example, use fslinfo if FSL is installed on your computer. Or, if you don’t have FSL, you can use VTK itself:
header = reader.GetNIFTIHeader()
print(header)
Anyway, once you’ve called reader.Update()
and reader.GetOutput().GetNumberOfScalarCompnents()
to ensure that the data has the expected number of components, you can try rendering each component as its own image:
reader.Update()
table1 = vtk.vtkLookupTable()
table1.SetRange(0, 255) # set according to the expected value range
table1.SetRampToLinear()
table1.SetHueRange(0.0, 0.0) # hue of 0.0 is red
table1.SetSaturationRange(1.0, 1.0) # make color bright as possible
table1.SetValueRange(0.0, 1.0)
table1.SetAlphaRange(1.0, 1.0)
table1.Build()
color1 = vtk.vtkImageMapToColors()
color1.SetLookupTable(table1)
color1.SetInputData(reader.GetOutput())
color1.SetActiveComponent(0) # for first volume
# then, display the output of color1, or feed it into
# vtkImageBlend to color-blend it with other volumes
The idea is that you can use SetActiveComponent( X ) to choose which component to apply the lookup table to. By using a different lookup table for each component, you can display each component with a different hue.
Also, if these volumes are probability maps (which is common for nifti files produced by FSL), you can call SetAlphaRange(0.0, 1.0) on the lookup table to cause it to map the probability values to opacity values. This is very useful for displaying probability maps on top of an image volume.
In any case, be sure to dump the file header, if you haven’t done so already, in order to see how the dim[] and pixdim[] have been set.