Add sform matrix to NIfTI-1 file
Many medical imaging software tools use NIfTI file format to save and process data. NIfTI format often uses quaternion representation of rotation matrix to represent the voxel locations as reported by the scanner (when qform_code>0 in NIfTI header). NIfTI format also has ability to define the location of the voxels in some standard space (which is often same as voxel location in scanner) using another matrix sform (when sform_code>0 in NIfTI header).
Some medical imaging softwares only read sform matrix for NIfTI input and can not work with quaternion representation. This tool can be used to add sform matrix to the NIfTI files so that they can be then used with different softwares. It write out sform matrix in a NIfTI file when qform_code>0 and when the NIfTI file does not have sform matrix set (sform_code<=0). It does not perform any operation on the image matrix and only modifies the NIfTI header to write correct sform matrix corresponding to the rotation matrix defined by quaternion.
This tool requires Matlab compiler runtime 2012a, which can be downloaded and installed from here. add_sform can be run from command line using following syntax:
Windows:
add_sform.exe dataFile outFile [--force]
Linux and Mac:
add_sform.sh dataFile outFile [--force]
where dataFile is the input NIfTI filename without sform matrix, outFile is the output NIfTI filename with sform matrix set. By default, the tool does not overwrite an existing sform matrix (when sform_code>0). The optional flag --force can be used to overwrite sform matrix even when it is defined in the header.
Download Links:
Author: Chitresh Bhushan