[Mrtrix-discussion] tracks2prob, sample and resample doubts

Donald Tournier d.tournier at brain.org.au
Thu Jun 9 17:33:24 PDT 2011


Hi Luis,

I've been digging a bit more in the rounding problem.

>
> It doesn't seem to be a problem of rounding. I modified a bit the
> source code so I was able to see through which voxels the streamlines
> goes.
>

Good to hear.


> And discovered that my problem was the offset in the srow matrix in
> the nifti was wrongly calculated. In my case my original image voxel
> size  is a 1.25, 1.25, 2.5 mm. If I'd like to reduce the voxel size to
> 1 mm and my transform matrix is as follows:
>
> Tm [0][0] Tm [0][1] Tm [0][2] Tm[0][3]
> Tm [1][0] Tm [1][1] Tm [1][2] Tm[1][3]
> Tm [2][0] Tm [2][1] Tm [2][2] Tm[2][3]
>
> I only have to change the field refering to images dimensions by
> multplying it by the previous voxel size, and dividing it by the new
> voxel size. In this case the first dimension multiplied by 1.25 and
> divided by 1. And so for the rest of dimensions.
>
> But I have to update the offset values in the transform matrix Tm
> [*][3] in some way cos as I've seen the values in the images produced
> by tracks2prob differs from the ones present in the template used (not
> so much just, between 0.125 and 0.75). So my question is if you could
> give a hand on this update and how is it supposed to be done.
>

Yes, dealing with transform matrices also gives me a headache. In your case,
I think the answer is thankfully pretty simple. Assuming you're sticking to
the same origin (i.e. the bottom corner of your dataset is still in the same
place with respect to real space), then the offset you're seeing is due to
the fact that technically the offset field provides the displacement from
the origin to the *middle* of the voxel at (0,0,0). If the actual corner is
to remain the same, you need to adjust the offset slightly to account for
that.

Basically, you want the outside edges of the voxel at (0,0,0) to remain the
same. These are at  (-Vx/2, -Vy/2, -Vz/2), where Vx, Vy, Vz are your voxel
sizes. So to maintain this position after a change of voxel size, the offset
needs to change by (Vx/2-Vx'/2, Vy/2-Vy'/2, Vz/2-Vz'/2), where Vx', Vy', Vz'
are the new voxel sizes. Given your voxel dimensions, this equate to a
correction of (0.125, 0.125, 0.75). which is precisely what you're seeing.



> And my other inquiry is that I modified the code and now I'm able to
> see the voxel traversed by a streamline I found a curious fact.
>
> I used your info function to print the voxel coordinates in:
>
> TrackMapper<Voxel>::voxelise (...) definition. (tracks2prob.cpp line 295)
>
> I print the coordinates returned by ->  interp.R2P(*i);
>
>
>
> And I checked everything with my matlab function and they are
> identical. But, here comes the tricky part, all the coordinates in the
> nifti image are one unit bigger than the ones captured before.
>
> If I track just one streamline and use tracks2prob, all the voxels
> which its value is one are the voxels traversed by the streamline so:
>
> ie:
>
> Capture coordinates in TrackMapper...
>
>
> x = 170, y = 30, z =3
> x = 170, y = 30, z =3
> x = 170, y = 31, z =3
> x = 170, y = 30, z =3
> x = 170, y = 30, z =4
>
> Voxels with value 1
>
> x= 171, y=31, z=4
> x= 171 y= 32, z=4
> x=171, y= 31, z=5
>
> All the coordinates are one unit bigger. Does it make any sense? Have
> I captured the voxel coordinates in the wrong place?
>
>
This depends on how you're displaying the coordinates in your Matlab
function. In MRtrix, everything is indexed from zero, whereas in Matlab,
indices start from 1. Does that explain the difference?

Cheers,

Donald.



>
> Best,
>
> Luis.
>
> On Fri, Jun 3, 2011 at 9:29 AM, Luis Morís
> <luis.moris.fernandez at gmail.com> wrote:
> > Hi Donald,
> >
> > Thanks a lot for your help.
> >
> > I have checked, and interpolation is set to 1, step size is default
> > 0.2 and voxel size of the map is 1 mm. So initially that's not the
> > problem.
> >
> > The maps are really similar but not identical. Big picture is the
> > same, but when you go and check voxel values, they are different. So
> > maybe it's due to rounding errors.
> >
> > Thanks again for your help, it has made things much more clear for me.
> >
> > Best,
> >
> > Luis.
> >
> > On Fri, Jun 3, 2011 at 7:15 AM, Donald Tournier <d.tournier at brain.org.au>
> wrote:
> >> Hi Luis,
> >>>
> >>> I'm trying to do a study with the streamlines produced by mrtrix.
> >>>
> >>> My idea is to create an image similar to the one produced by
> >>> tracks2prob, but I have bumped into some problems.
> >>>
> >>> I have created a function similar to tracks2prob into matlab. The idea
> >>> is really simple take the coordinates provided by streamtrack, and
> >>> load them into matlab (no problem here). Afterwards transform these
> >>> coordinates into voxel space, by using the transform matrix in the dwi
> >>> image, I round up the values and have the correct voxel coordinates.
> >>> But here I get a similar, but not identical, image as the one provided
> >>> by tracks2prob, I have checked the source code and it seems that this
> >>> process is not so straightforward, because some interpolation is made
> >>> along the way.
> >>>
> >>> Could you explain the differences between my process and your process?
> >>> Is my idea correct or interpolation is a must fot the image to be
> >>> correct?
> >>
> >> It sounds like you've got the right idea. I expect the differences you
> see
> >> are minimal? If not, then it could be due to the interpolation aspects.
> >> Basically, the interpolation that takes places is a resampling of the
> >> tracks, and by default it only happens if the step size is larger than
> half
> >> the voxel size. This is to avoid voxels being missed due to the sampling
> of
> >> the tracks being too coarse. You can check if this happening in your
> case by
> >> running the command with the "-info" option. It should then display a
> line
> >> stating what interpolation factor is actually being used (1 is no
> >> interpolation).
> >> If you weren't using interpolation, then there shouldn't be any
> difference
> >> between your output and tracks2prob's, apart potentially from slight
> >> differences caused by rounding errors. MRtrix operates on 32-bit floats,
> >> whereas I'd expect Matlab to operate on 64-bit doubles. This may cause
> >> slight differences which would be enough for some of the points to be
> >> assigned to different voxels. So basically, if the differences are
> limited
> >> to the odd voxel here and there, that's probably what the problem is.
> >> Otherwise, I'm not too sure...
> >>
> >>>
> >>> Is there a way of knowing which tracks are going through which voxel?
> >>
> >> If you're asking, is there a command in MRtrix to do this, the answer is
> no,
> >> there is no such application.
> >>
> >>>
> >>> Or wich voxels do a track pass trough?
> >>
> >> To find out which voxels a track pass through can be done using
> tracks2prob,
> >> if you can generate a track file with just the track you're interested
> in.
> >> You might be able to do this with a combination of "track_info -ascii"
> and
> >> "import_tracks".
> >>
> >>>
> >>> One of the parts of my study is related not only to the density of
> >>> tracks in a voxel, but with some scalars that will weight this density
> >>> or the contrary these scalar will be weighted by the track density.
> >>> i.e. Something similar to "The average pathlength map: a diffusion MRI
> >>> tractography-derived index for studying brain pathology. Pannek et
> >>> al." But for this purpose if I'm not wrong I need to know which tracks
> >>> pass through which voxel in order to calculate the average length of
> >>> the tracks that goes through a given voxel.
> >>
> >> We've recently submitted a manuscript on a similar topic. You're right,
> to
> >> do this you'll need to know which tracks go through each voxel.
> >>
> >>>
> >>> So that's why I ask if there's some way of getting this information
> >>> with mrtrix. I can do it with matlab, but as far as my method is not
> >>> similar to the one you use I want to make sure my approach is correct.
> >>
> >> Glad to hear it - this would be much better done in Matlab than using a
> >> combination of existing MRtrix commands...
> >>
> >>>
> >>> And a last question about sample and resample, if I have another image
> >>> for example Linear Anisotropy, I can use sample_tracks to obtain the
> >>> interpolated value of LA on each of the points of the track. And then
> >>> calculate for example the average LA in a given track. But as I've
> >>> read on the doc sample_tracks should be used with tracks produced by
> >>> resample_tracks to ensure even sampling. Why is that? Does not the
> >>> step size of 0.2 mm in streamtrack provide an even sampling? If I set
> >>> the -num (number of samples) parameter in resample_tracks to 100, All
> >>> tracks will have 100 points? Does that not do uneven sampling on
> >>> different size tracks? I mean do a 20 mm track have 100 samples, and a
> >>> 200 mm track also 100 samples?
> >>
> >> There is no problem with using "sample_tracks" if you're simply
> interested
> >> in the average value over the tracks. The "resample_tracks" application
> just
> >> tries to ensure that for a set of tracks, all the sampling points are
> >> roughly equivalent in terms of their position along the track. This is
> of
> >> interest if you're interested in averaging values across tracks at
> >> corresponding positions. Not a problem in your case. I might amend the
> >> documentation for sample_tracks to avoid any further confusion...
> >> Cheers,
> >> Donald.
> >>
> >> --
> >> Jacques-Donald Tournier (PhD)
> >> Brain Research Institute, Melbourne, Australia
> >> Tel: +61 (0)3 9035 7033
> >>
> >>
> >
> _______________________________________________
> Mrtrix-discussion mailing list
> Mrtrix-discussion at www.nitrc.org
> http://www.nitrc.org/mailman/listinfo/mrtrix-discussion
>



-- 
Jacques-Donald Tournier (PhD)
Brain Research Institute, Melbourne, Australia
Tel: +61 (0)3 9035 7033
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.nitrc.org/pipermail/mrtrix-discussion/attachments/20110610/7c280e2c/attachment.html


More information about the Mrtrix-discussion mailing list