Just to add -
My input image has a qform_code of 1 and an sform_code of 0.
> SPM assumes that each volume has a single "voxel-to-world" affine
> mapping associated with it. If sform_code is defined, then SPM will
> use the sform matrix - otherwise it will use the qform matrix. If the
> qform_code is not defined, then anything can happen. For this reason,
> it is a very good idea to ensure that at least one of these matrices
> contains accurate information.
I had a look at some of the code in nifti.m and related stuff in the
@nifti directory, but could not find evidence that the qform matrix is