Hi Jesper,
I finally got around to writing the code to do this with your help on the eddy website (including a simulation where I rotated some data and the associated b-vectors, run it through eddy, then test this correction, happy to share this as well if desired). I am able to verify the code below works well for single-angle rotation. However, the traditional X and Y rotations are swapped compared to the conventional rotation matrices, and there are some sign differences. While I am sure this works for single angles, I cannot with my simulated data confirm if the correct order should be inv(RxRyRz) as per your website, or inv(RyRxRz) given my nomenclature below. Based on your website, I would expect it should be inv(RyRxRz) to match what you say column-wise. Thank you for any help you could offer in advance.
trans=dlmread('align.eddy_parameters');
bvecsRot=dlmread('temp-rot.bvec');
for t=1:size(trans,1)
ang=trans(t,6);
rzm=[[cos(ang) -sin(ang) 0];...
[sin(ang) cos(ang) 0];...
[0 0 1]];
ang=trans(t,5);
rxm=[[1 0 0];...
[0 cos(ang) -sin(ang)];...
[0 sin(ang) cos(ang)]];
ang=trans(t,4);
rym=[[cos(ang) 0 sin(ang)];...
[0 1 0];...
[-sin(ang) 0 cos(ang)]];
invrot=inv(rym*rxm*rzm);
bvecsUnrot(:,t)=((bvecsRot(:,t)')*invrot)';
end
dlmwrite('temp-unrot.bvec',bvecsUnrot,' ');
|