Apply deformation field without affecting the intensities
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I am working with Volumes (3D matrices), and I have got geometric transformation and displacement fields from the function imregtform. My moving image and fixed image are binary images (0s and 1s). Now I want to apply the same geometric transformation (or the displacement field) to another version (this version is not binary image) of moving image. I do not want to use imwarp as it changes the values (intensities) in the image. So, I would like to apply the transformation without affecting the values in image.
I have written the following MATLAB function to do the same using the Displacement field:
function [ Volumeafterd ] = ApplyDeformation2Volume( Volume, Deformation , OPFilename)
% Detailed explanation goes here
%%Check the Size
SizeD = size(Deformation);
SizeV = size(Volume);
Volumeafterd = zeros(SizeV(1),SizeV(2),SizeV(3));
if SizeV(1) == SizeD(1) & SizeV(2) == SizeD(2) & SizeV(3) == SizeD(3)
%%Apply the Deformation
fnd = find(Volume~=0);
counterd1=0;
for it=1:length(fnd)
[x,y,z] = ind2sub(SizeV,fnd(it));
d1 = squeeze(Deformation(x,y,z,:));
x1=round(x+d1(1));y1=round(y+d1(2));z1=round(z+d1(1));
if x1<1 | y1<1|z1<1
fprintf('Non positive index (D1) for x %d, y %d, z %d adding %d,%d,%d to get x %d,y %d,z %d\n'...
,x,y,z,d1(1),d1(2),d1(3),x1,y1,z1);
end
if (x1>=1 & y1>=1 & z1>=1)
if (Volumeafterd(x1,y1,z1)~=0)
%fprintf('Over writing %d %d %d\n',x1,y1,z1);
counterd1 = counterd1+1;
end
Volumeafterd(x1,y1,z1) = Volume(x,y,z);
end
end
fprintf("Overwritten counter : %d\n",counterd1);
else
fprintf("The size of Deformation field and the volume does not match\nThe output will be empty Volume \n");
end
end
I have also tried using the tform. Both the functions return the same output which is expected. But they do not replicate what imwarp does (in terms of geometric translation). It would be great help if someone can point out my mistake, or guide me with another way.
Thanks.
0 Kommentare
Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!