# Coordinate transformation and use as seeds

Hi to everyone!

I am new to MRtrix3 and I am facing a problem. I have a set of cortical points derived from anatomical 3d T1 in a subject which I would like to use as seeds to construct tracts.

My first question is how can I locate those points in mrtrix since – as fas as I understand – the coordinates have been transformed? Is there a way to transform my set of point coordinates (from anatomical 3D T1 space) to a form that mrtrix can use?

And if so, as a second step, is it possible to create a mask from this set of points in order to use it as seed for track construction?

Hello!

Someone else will be able to give you a more concrete answer to your questions, but in the meantime maybe I can share some pointers that might help…

Regarding coordinate transformation, it should be straightforward to get your cortical points in the right format, but I’m not sure what you mean by “anatomical 3D T1” so I can’t give you a specific answer for your situation. If your coordinates are in voxel space (i.e. your points are given as image voxel indices), then you should be able to transform them to “scanner space” (in units of mm) using the image transform and voxel sizes. Some information here and, if you want to get really stuck in (and confused!), here.

Regarding creating you seed mask, this should be doable using the `mredit` command. In fact, `mredit` allows you to provide your coordinates in either voxel or scanner space. So you could create your mask from some voxel coordinates e.g. p_1 = (10, 20, 35)^T, p_2 = (10, 20, 36)^T using something like

``````mredit mask.mif -voxel 10,20,35 1 -voxel 10,20,36 1 # Beware, edits image in place!
``````

(where `mask.mif` is intially all zeros) although this could get tedious if you have many points! If using linux, I like to use `printf` when I need to use the same argument flag over and over. So for example if you put all your coordinates in a text file “`coords.txt`” like this

``````39,63,36
37,63,38
41,63,38
``````

then you can do `mredit mask.mif \$(printf "-voxel %s 1 " \$(cat coords.txt))`. I’m sure there are similar options for Windows.

Hope that helps!

Fiona

If you want to use coordinates for `-seed_sphere`, I think that’s a bit tricky to achieve with MRtrix tools alone but can be done with a small C++ command:

First, make sure your coordinates are in scanner space of the T1w image (mrview → view tool. BTW you can copy these by pressing the copy button which also prints them to the terminal.)

To get these coordinates into the scanner space of the dMRI image, you could try out this command (untested):

It takes in a text file with scanner space coordinates (x,y,z per row) and a warp and outputs the warped locations. You’d need to use the inverse warp compared to what you’d use for transforming the T1w to dMRI space. If you don’t have a warp but only a linear transformation, see: linear transform track file - #2 by maxpietsch

Either copy the `coordinatewarp.cpp` file into your `mrtrix3/cmd` directory and run `./build` or make an external module.

Fiona, thank you very much for you immediate response!

As for the coordinates, by anatomical 3D T1 I mean the T1w image for the subject. Let’s say I choose a specific point with coordinates x=101, y=155.5, z=86 (MRI coordinates) in a viewer (other than mrview). When I click on the same point in T1w in mrview the coordinates are: voxel index [201,83.6662,151.789] and position [5.18719,-28.4457,-1.58521] mm. The properties of the image (mrinfo) has a transform matrix as follows:
1 0 0 -95.3128051757812
0 1 0 -112.111915588379
0 0 1 -153.373733520508.
I provide you some screenshots…

(other viewer)

(mrview)

My question is how can I convert my set of coordinates (that are in accordance with the first x,y,z values I provided - MRI coordinates) so as to be meaningful for MRtrix?

As a matter of fact I need to create a mask from about 200 points (I think they are a lot). But I’ll give a try to both methods you suggested (my OS is ubuntu linux) when I get the coordinates right.

Ioannis

I guess that there is a disagreement between my coordinates and the ones I see on MRtrix - I provided some screenshots). That is my first issue.

I am really new to MRTrix and image processing, so I’ll have to get more into it to better understand and implement your recommendation.

I was wondering if this could be done by selecting a set of points from ROI editor and then use them as a single ROI to seed streamlines from it.

Thank you for your interesting posts!

Ioannis

Hi Ioannis

Yes this is pretty standard and easy to do with MRtrix. You can use the ROI tool in `mrview` to create, draw and save an ROI image, and then use that as the seed ROI in `tckgen` by using `-seed_image your_roi.mif`. If you’re happy to manually draw your specific points in the viewer and save the file, this is probably the easiest option. If however you’ve got a very specific set of coordinates (e.g. from some other processing step or tool) then you can use the methods suggested above to create a seed mask from your list of coordinates.

Again, I’m afraid this still doesn’t help me understand what coordinate system this other viewer is using ! Unfortunately there’s lots of confusing terminology and different conventions, so one has to be very specific… It looks like the viewer is giving you a drop down menu with different coordinate system options? The documentation for that software should be able to give you a more specific definition for those different options. I can try and help you understand what the various numbers in mrtrix mean.

Since your transform matrix doesn’t contain a rotation component, the voxel index i and position p are related as p = i*s + o , where the final column in the matrix is your offset o (in mm) between the corner of the image to the centre of the scanner coordinate system, and s is the voxel size s (also in the header). Based on the numbers you provided, I guess your voxel size is ( 0.5 x 1 x 1 )mm?

Now as for your “MRI coordinates” voxels from the other viewer, my closest guess is that they may be in image coordinates, which is the voxel index scaled by the voxel size, i.e. i*s. However, if I divide your “MRI coordinates” values by the (guessed) voxel size 0.5x1x1, I get [202., 155.5, 86.] which is pretty close to the voxel values reported in mrivew, except that the y and z values are swapped… . So either my guess is wrong or there’s more to the story, e.g. strides, rotation etc…

All this might be irrelevant though, if you’re happy with to just use the ROI tool in mrview to draw and save your seed ROI

Fiona

Hi Fiona!

Ok! That seems straightforward! And the voxel coordinates that occur with the division you mentioned seem closer to the expected ones (with the y and z swap - I don’t know why this is happening, but I’ll take a look at the specifications of the other viewer when I have the chance).

In the case there was a rotation component? Can you provide me a type for this?

You are right. That is the voxel size!

Now that I can have the cooordinates “right”, I tried to follow the next step…mask creation, but I couldn’t find a way to create a mask.mif with all zeros (is it a blank image?).
As a matter of fact, I tried to use the method you proposed (printf and coords.txt) on the initial T1_raw.mif, but I get an error - I guess I shounldn’t use the T1_raw.mif file.

Thanks for all the help so far and your patience!

Ioannis