Closed jchoude closed 3 years ago
Hi JC, what do you suggest, shall we use nibabel.streamlines
or dipy.io.streamlines
? I'm a bit lost.
Also, we made few tries with the nibabel.streamlines
interface, and we are puzzled. If we load a tractogram and then re-save it right after, the coordinates are being changed by this operations. For example:
trk_file = nibabel.streamlines.load( 'fibers.trk' )
streamlines_out = trk_file.streamlines
affine = nibabel.streamlines.trk.get_affine_trackvis_to_rasmm( trk_file.header )
tractogram_out = nibabel.streamlines.tractogram.Tractogram( streamlines=streamlines_out, affine_to_rasmm=affine )
nibabel.streamlines.save( tractogram_out, 'fibers__MOD.trk' )
but the two files have different content (a shift). We tried with different affine matrices, e.g. identity, but the problem is not solved. Any clue?
Hi Alessandro,
I think the simplest way is to use dipy.io.streamlines
, since it will keep track of the space for you.
However, in your specific case, without having direct access to the file to validate what I'm saying, the first issue is that the nibabel.streamlines
API always loads your streamlines in world (RASMM) space. In this case, since you don't change that space with your other modifications, you should instead use:
tractogram_out = nibabel.streamlines.tractogram.Tractogram( streamlines=streamlines_out, affine_to_rasmm=numpy.eye(4) )
,
since your streamlines are already in world space. In your use case, using affine_to_rasmm=affine
will apply an additionnal transform. Instead, you should use numpy.eye(4)
, and then save as
nibabel.streamlines.save( tractogram_out, 'fibers__MOD.trk', header=trk_file.header )
where the header should correctly save them (as long as the content of the original header made sense).
If it still doesn,t work, feel free to write offline with a file and I'll check if something weird is happening.
The
nibabel.trackvis
interface is deprecated and will be removed in version 4 of Nibabel.In its place, it is recommended to use
nibabel.streamlines
.You could also use the new
dipy.io.streamlines
includingStatefulTractogram
, which provides more space checks.