Reputation: 433
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
Upvotes: 0
Views: 775
Reputation: 5821
The format of your affine matrix looks fine if you are using it to operate on column vectors, as in [X; Y; Z; 1] = T*[x; y; z; 1]
. The reason MATLAB's example is transposed is because it operates on 1x4
row vectors, as in [X, Y, Z, 1] = [x, y, z, 1]*(T')
.
As for the the actual numbers in the matrix, I can't comment since I don't know the original images. I do notice that there is an x-translation of -61.6055
, which seems pretty big for the sizes of the images you have. Do you know for sure this is the right answer?
I'd suggest maybe starting with a simple pair of images where you know the answer beforehand (maybe white squares on a black background drawn in Paint) to confirm your registration algorithm gives the right answer.
Upvotes: 1