Skip to content

nib.get_header() return negative dim #548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Stuming opened this issue Jul 28, 2017 · 5 comments
Closed

nib.get_header() return negative dim #548

Stuming opened this issue Jul 28, 2017 · 5 comments

Comments

@Stuming
Copy link

Stuming commented Jul 28, 2017

when I tried to use nibabel to get data from fmcpr.up.sm0.self.lh.nii.gz, which was created through freesurfer preproc-sess -surface self command, I get -1 in dim, like this: dim : [ 4 -1 1 1 451 1 1 1], which actually has 140k vertex if checked by mri_info.

It seems due to the limitation of Nifti1, the dim cannot larger than 32k, and I tried mri_convert *.nii.gz *.mgz could fix this, but it may be helpful for others if nibabel could get data from these negative dim file. And if freesurfer could write files by Nifti2 format, this could also be solved.

Thanks for your reading:)

@effigies
Copy link
Member

effigies commented Jul 28, 2017

What version of nibabel are you using? From what I can see in the header you posted on the FreeSurfer/neuroimaging@python lists, this case should be handled by the large vector hack.

What do you get from:

import nibabel as nib
img = nib.load('fmcpr.up.sm0.self.lh.nii.gz')
print(img.shape)

Edit: And is there any chance you could make this image available?

@Stuming
Copy link
Author

Stuming commented Jul 28, 2017

Thanks for your reply, my nibabel version got by dpkg --list |grep nibabel is python-nibabel 1.2.2-1.

As to the command, I also tried img.get_data(), see below:

 >>>import nibabel as nib
 >>>img=nib.load('fmcpr.up.sm0.self.lh.nii.gz')
 >>>img.get_shape()
(-1, 1, 1, 451)
 >>>img.get_data()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/pymodules/python2.7/nibabel/spatialimages.py", line 341, in get_data
    return np.asanyarray(self._data)
  File "/usr/lib/python2.7/dist-packages/numpy/core/numeric.py", line 512, in asanyarray
    return array(a, dtype, copy=False, order=order, subok=True)
  File "/usr/lib/pymodules/python2.7/nibabel/arrayproxy.py", line 55, in __array__
    self._data = self._read_data()
  File "/usr/lib/pymodules/python2.7/nibabel/arrayproxy.py", line 60, in _read_data
    data = self.header.data_from_fileobj(fileobj)
  File "/usr/lib/pymodules/python2.7/nibabel/analyze.py", line 486, in data_from_fileobj
    data = self.raw_data_from_fileobj(fileobj)
  File "/usr/lib/pymodules/python2.7/nibabel/analyze.py", line 458, in raw_data_from_fileobj
    return array_from_file(shape, dtype, fileobj, offset)
  File "/usr/lib/pymodules/python2.7/nibabel/volumeutils.py", line 493, in array_from_file
    raise IOError(msg)
IOError: Expected -1804 bytes, got 264722568 bytes from file "fmcpr.up.sm0.self.lh.nii.gz"
 - could the file be damaged?

And I get the real dim by mri_info:

 $ mri_info fmcpr.up.sm0.self.lh.nii.gz 
Volume information for fmcpr.up.sm0.self.lh.nii.gz
          type: nii
    dimensions: 146742 x 1 x 1 x 451
   voxel sizes: 1.0000, 1.0000, 1.0000
          type: FLOAT (3)
           fov: 146742.000
           dof: 0
        xstart: -73371.0, xend: 73371.0
        ystart: -0.5, yend: 0.5
        zstart: -0.5, zend: 0.5
            TR: 2000.00 msec, TE: 0.00 msec, TI: 0.00 msec, flip angle: 0.00 degrees
       nframes: 451
       PhEncDir: UNKNOWN
ras xform present
    xform info: x_r =  -0.9993, y_r =   0.0257, z_r =   0.0279, c_r =     2.3984
              : x_a =   0.0205, y_a =   0.9848, z_a =  -0.1727, c_a =    12.6375
              : x_s =   0.0319, y_s =   0.1720, z_s =   0.9846, c_s =    31.7090
Orientation   : LAS
Primary Slice Direction: axial

voxel to ras transform:
               -0.9993   0.0257   0.0279 73320.5703
                0.0205   0.9848  -0.1727 -1491.6578
                0.0319   0.1720   0.9846 -2310.5237
                0.0000   0.0000   0.0000     1.0000

voxel-to-ras determinant -1

ras to voxel transform:
               -0.9993   0.0205   0.0319 73372.1328
                0.0257   0.9848   0.1720   -17.4596
                0.0279  -0.1727   0.9846   -28.6050
                0.0000   0.0000   0.0000     1.0000

@effigies
Copy link
Member

I would strongly recommend upgrading to 2.1.0. If you're using Debian/Ubuntu, NeuroDebian contains many up-to-date packages, including nibabel.

@effigies
Copy link
Member

effigies commented Jul 28, 2017

Fixed in #332 / 24431eb. The first release to include it was 2.0.2.

@Stuming
Copy link
Author

Stuming commented Jul 28, 2017

Yes, I install nibabel by apt-get, before now I think apt-get would provide the newest version to me, it seems I'm wrong thanks for your advice, and I would upgrade to 2.1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants