Skip to content
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

nibabel.load problem with mri_vol2surf nifti output #100

Closed
agramfort opened this issue Apr 10, 2012 · 9 comments
Closed

nibabel.load problem with mri_vol2surf nifti output #100

agramfort opened this issue Apr 10, 2012 · 9 comments
Labels

Comments

@agramfort
Copy link
Contributor

the following file produces an error with nibabel.load:

http://dl.dropbox.com/u/2140486/bad2.nii

FYI it was produced with freesurfer mri_vol2surf

@matthew-brett
Copy link
Member

Not for me. What nibabel are you using? What platform are you on?

@agramfort
Copy link
Contributor Author

it fails with current master on both my mac and my ubuntu box.

Try:

import nibabel as nib
nib.load('bad2.nii').get_data()

I get an IOError:

...
496 % (datasize, len(data_str), file_str) +
497 ' - could the file be damaged?'
--> 498 raise IOError(msg)
499 arr = np.ndarray(shape,
500 in_dtype,

IOError: Expected -4 bytes, got 661100 bytes from file "bad2.nii"

  • could the file be damaged?

@matthew-brett
Copy link
Member

Hmm - sorry - I didn't try to load the data. Looking at the header, it claims dimensions of -1, 1, 1 which I guess must be wrong. FSL also barfs on this:

[mb312@tom ~/Downloads]$ fslinfo bad2.nii
** ERROR: nifti_convert_nhdr2nim: bad dim[1]
** ERROR (nifti_image_read): cannot create nifti image from header 'bad2.nii'
** ERROR: nifti_image_open(bad2): bad header info
ERROR: failed to open file bad2
ERROR: Could not open file

I guess it would be good to have a more helpful error message though.

@agramfort
Copy link
Contributor Author

FYI this nii file contains a 1d vector (shape 165275 x 1 x 1)
corresponding to a surface projection on one hemisphere.

freesurfer mri_info says:

$ mri_info bad2.nii
Volume information for bad2.nii
type: nii
dimensions: 165275 x 1 x 1
voxel sizes: 1.0000, 1.0000, 1.0000
type: FLOAT (3)
fov: 165275.000
dof: 0
xstart: -82637.5, xend: 82637.5
ystart: -0.5, yend: 0.5
zstart: -0.5, zend: 0.5
TR: 0.00 msec, TE: 0.00 msec, TI: 0.00 msec, flip angle:
0.00 degrees
nframes: 1
PhEncDir: UNKNOWN
ras xform present
xform info: x_r = -1.0000, y_r = 0.0000, z_r = 0.0000, c_r = 2.7109
: x_a = 0.0000, y_a = 0.9796, z_a = 0.2011, c_a = 20.1731
: x_s = 0.0000, y_s = -0.2011, z_s = 0.9796, c_s = 14.8075
Orientation : LAS
Primary Slice Direction: axial

voxel to ras transform:
-1.0000 0.0000 0.0000 82640.2109
0.0000 0.9796 0.2011 19.5827
0.0000 -0.2011 0.9796 14.4182
0.0000 0.0000 0.0000 1.0000

voxel-to-ras determinant -1

ras to voxel transform:
-1.0000 0.0000 0.0000 82640.2109
0.0000 0.9796 -0.2011 -16.2836
0.0000 0.2011 0.9796 -18.0614
0.0000 0.0000 0.0000 1.0000

@matthew-brett
Copy link
Member

OMG that's horrible. It looks like freesurfer is extending the nifti1 standard to look for -1 in the dim field, and, if present, using the glmax field as the vector length. I can't see any specific documentation for this, but found:

http://code.google.com/p/fieldtrip/source/browse/trunk/external/freesurfer/save_nifti.m?spec=svn5022&r=5022#77

If we're going to support that we should discuss it on the list; that's painful.

@agramfort
Copy link
Contributor Author

OMG that's horrible.

:)

It looks like freesurfer is extending the nifti1 standard to look for -1 in the dim field, and, if present, using the glmax field as the vector length.    I can't see any specific documentation for this, but found:
http://code.google.com/p/fieldtrip/source/browse/trunk/external/freesurfer/save_nifti.m?spec=svn5022&r=5022#77

it looks like a pb with an uint16 used to store the dim in nifti1 format...

If we're going to support that we should discuss it on the list; that's painful.

my work around was to use .mgz and use the nibabel mgz io to make this
work. I feel it would be nice to support this with nifti1 too although
is a bit of a hack...

can you send the email on the ML?

@matthew-brett
Copy link
Member

@agramfort - can you check this works for you? It does on bad2.nii

@dgwakeman
Copy link

I have found that I cannot read these files when they are very large using version
nib.version | '1.3.0'
e.g. the dimensions are:
163842 x 1 x 1
It reads fine in FreeSurfer, but not in nibabel:
np.shape(x)
(27307, 1, 6, 1)

@matthew-brett
Copy link
Member

Hi Dan - sorry - I was in Cuba and mostly out of internet. Can you try the latest development version? If that doesn't work, or you can't try it, is there an example file you can put somewhere I can get it?

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

No branches or pull requests

3 participants