[Neuroimaging] reg. load nifti image

Matthew Brett matthew.brett at gmail.com
Thu Jan 21 03:51:41 EST 2016


Hi,

On Wed, Jan 20, 2016 at 7:36 PM, Raghav Mehta
<raghav.mehta at research.iiit.ac.in> wrote:
> Hi,
>
> I am trying to read Nifti images using Nibabel, but when I am using nib.load to load the file from perticlar dataset I am getting following error:
>
> Traceback (most recent call last):
>   File "<input>", line 1, in <module>
>   File "/usr/local/lib/python2.7/dist-packages/nibabel/loadsave.py", line 44, in load
>     return guessed_image_type(filename).from_filename(filename, **kwargs)
>   File "/usr/local/lib/python2.7/dist-packages/nibabel/keywordonly.py", line 16, in wrapper
>     return func(*args, **kwargs)
>   File "/usr/local/lib/python2.7/dist-packages/nibabel/analyze.py", line 986, in from_filename
>     return klass.from_file_map(file_map, mmap=mmap)
>   File "/usr/local/lib/python2.7/dist-packages/nibabel/keywordonly.py", line 16, in wrapper
>     return func(*args, **kwargs)
>   File "/usr/local/lib/python2.7/dist-packages/nibabel/analyze.py", line 956, in from_file_map
>     img._affine = header.get_best_affine()
>   File "/usr/local/lib/python2.7/dist-packages/nibabel/nifti1.py", line 642, in get_best_affine
>     return self.get_qform()
>   File "/usr/local/lib/python2.7/dist-packages/nibabel/nifti1.py", line 822, in get_qform
>     quat = self.get_qform_quaternion()
>   File "/usr/local/lib/python2.7/dist-packages/nibabel/nifti1.py", line 797, in get_qform_quaternion
>     return fillpositive(bcd, self.quaternion_threshold)
>   File "/usr/local/lib/python2.7/dist-packages/nibabel/quaternions.py", line 99, in fillpositive
>     raise ValueError('w2 should be positive, but is %e' % w2)
> ValueError: w2 should be positive, but is -6.401211e-07
>
>
> I know this due to fill option in quaternions.py file. My question is how can I disable that option and read these files.
>
> This issue is only for this perticular dataset. I am able to read other files normally from other dataset. Can anyone help me in solving this issue??

It looks like our threshold is too strict here.

Does this work?

>>> import numpy as np
>>> import nibabel as nib
>>> nib.Nifti1Header.quaternion_threshold = np.finfo(np.float32).eps * 10
>>> img = nib.load('bad_image.nii')

?

Best,

Matthew


More information about the Neuroimaging mailing list