I am trying to register two volumes(vol1
and vol2
). The size of the vol1
is 40x40x24
. The size of the vol2
is 64 x64x11
.
So far, I have extracted their features and then matched them. Now, I have a set of corresponding points in two volumes that is stored in pairs
which is a matrix of size 100x6
(every row of pairs
is [x y z X Y Z]
where (x,y,z)
are the coordinates of a voxel in vol1
and [X Y Z]
is the corresponding voxel in vol2
). Then, using RANSAC algorithm, I have calculated the 3D affine transform, T. For example, T is something like below:
T=
2.7791 0.8204 0.7561 -61.6055
-0.4418 2.2663 -1.9882 29.0375
-0.2120 0.6568 -0.7041 6.2702
0 0 0 1.0000
I have a couple of questions. First, does this affine transformation matrix look correct? It looks correct to me. If it is correct then why the function affine3d in MATLAB which calculates the 3D affine transform has the column of zeroes instead of the row of zeroes (like in T above)? It looks like the transpose of my transform T.
If my transform is correct then another problem occurs. I tried to resample vol1 using transform T, but the calculated voxel coordinates are negative!!! I am so confused. I do not know what causes this problem.
Here, is my code. Please let me know if you see any problem with it.
function [ vol1R ] = resampling(vol1, vol2, T)
[size1, size2, size3] = size(vol2);
vol1R = zeros(size1,size2,size3); % Initializing registered vol1
for i= 1:size1
for j= 1:size2
for k = 1:size3
V = [i;j;k;1]; % V is the coordinates of a voxel on the registered vol1
% correspoding to voxel v on the vol1
% V = T * v : Relationship between v and V
v = T\V; % Problem occurs here!!!!!!! v has some negative values
% v (coordinates in vol1)
% continue
end
end
end