Hi! First of all, thank you once again for this amazing program!
I have one question. How can I rotate ONLY X-axis, and by only 90 degrees.
We have acquired a bunch of images with bruker machine, and somehow mrview and fslview just show me wrong sections. For example: where there should be axial, there is corronal section, and in saggital section, it is flipped AP.
I have noticed that when I rotate (using DSI studio) x axis by 90 degrees, everything turns out fine.
Same thing happens when I convert in ITK-snap orientation from LPI to LIA.
Basically, if I got it right, rotating x axis by 90, is same as doing swap y and z, and than inverting y?
I would like to know how can I just do that in mrtrix more quickly. Thanks in advance!
When it comes to erroneous importing of images, personally I tend to think about it in terms of axes being permuted or flipped, as opposed to rotations around axes. This is also probably the easier way to apply the corrections in MRtrix3:
mrconvert has the
-axes option, which enables (among other things) permutation of axes. So for instance, to switch the Y and Z axes, you would use:
mrconvert -axes 0,2,1.
mrtransform has the
-flip option, which enables flipping of a specific axis.
Play with the combination of these two until you get the correct result.
The other, less “friendly” approach, is to construct the appropriate transformation matrix in a text editor, and apply it using:
mrtransform -linear. However you need to be confident in handling such data (and figuring out what to change if you don’t get it right the first time) if you want to try this approach.
Hi Robert, thank you for your fast answer!
After trying what you have recommended I get an error:
“[ERROR]: ommited axis “3” has dimension greater than 1”
Really in front of a wall right now
mrconvert -axes 0,2,1
mrconvert -axes 0,2,1,3
to switch the Y and Z axes if you have 4D images.
That’s simply because
mrconvert needs to know how to re-order all non-singleton axes. This is presumably a 4D image, but you’ve only supplied 3 axes for the output - so
mrconvert reports that you’ve omitted one axis. The reason for the slightly cryptic message is that if the 4th dimension had size one (e.g.
dim: 128 x 128 x 90 x 1), it would correspond to a single 3D volume, and
mrconvert would treat it as such, and allow you to omit that axis. Might need to think of a slightly less confusing way of phrasing that…
In any case, try
mrconvert -axes 0,2,1,3 instead.
Alternatively, as Rob said, rotate the header transformation with
mrtransform -linear trafo.txt input.mif output.mif.
Content of trafo.txt should be something like:
1 0 0 0
0 0 -1 0
0 1 0 0
0 0 0 1
or the transpose of that.
Some kind of “Donald is typing…” symbol would be useful for the forum
I thought the same when I saw your post (after I’d hit ‘reply’, obviously…).
Guys what can I say… You solved my problem!!
There are no words how can I express how thankfull I am!! You really spared me headaches and troubles!!
Keep up with the good work
I would like to add a question regarding rotating around the x-axis. I am able to do a 90 degree rotation with the matrix maxpietsch provided in the above discussion. If I plot the input and the rotated image with mrview, you can nicely see a 90 degree rotation.
However, I want to do a 45 degree rotation around the x-axis. Therefore, I created the following matrix:
1 0 0 0
0 0.70710678 -0.70710678 0
0 0.70710678 0.70710678 0
0 0 0 1
However, if I use this matrix to rotate an image with mrtransform, the output image is still in the same position as the input image when I plot it with mrview. I do however see that the transform matrix in the header has changed. So there seems to be happening something different than with the 90 degree rotation. I do not understand why. Is it possible to do a rotation of 45 degrees while keeping the transform matrix in the header constant (zeros with ones at the diagonal) and thus visualize the rotation with mrview?
I think you may have fallen for a common trap with
mrview. This is something we really should think about making more prominent in the documentation somehow; I’ve also thought about implementing something in the software to make this effect more obvious, but such things regularly fall off the priority list.
I suspect what you’re doing is opening both images within
mrview, and then switching between them. The problem here is that every time you switch from one image to another, the
mrview “camera” automatically rotates in order to align itself with the closest axes of the new image. This is done so that when
mrview is operating in its standard “slice” view, when you change from one image to another, you are still looking at a “slice” of data within the newly shown image. So the reason it looks like the images are in the same position is because the camera is rotating to compensate for the change in position.
There are two ways this can be demonstrated:
Turn off the “snap to axes” button in the
mrview toolbar. Now, when you change images, what is shown in the viewer is an interpolation of the new 3D volume through the 2D plane defined by where the camera had been set for the previous image.
Load only one of the two images into
mrview, and instead load the second image using the Overlay tool.
But if I’m wrong in my diagnosis let us know.
Thank you for taking the time to look into my question. I think your suggestion is indeed what was happening.
I opened my 3 images (original, 45 degrees rotation and 90 degrees rotation) separately in mrview. So open an image in mrview, close mrview and then open another image in mrview. The original and 45 degree rotated image looked similar, but the 90 degree rotated image is rotated. So it seemed to me that my 90 degree rotation worked, but my 45 degree rotation did not (although the transformation matrix in the header was changed). However, when I overlay the 45 degree rotated image on the original image as you suggested, I could see that it was 45 degrees rotated.
Thanks again for your explanation!
Hello @david142, I first used permute from MATLAB, and then mrtransform and mrconvert will work fine. Many Thanks.