问题
I am using image registration toolbox to register two 3D images. I register the moving image to the fixed image. I use "imregtform" to save tform.
tform = imregtform(moving,fixed,transformType,optimizer,metric)
for example this is my 'tform':
1.0235 0.0022 -0.0607 0
-0.0276 1.0002 0.0089 0
-0.0170 -0.0141 1.1685 0
12.8777 5.0311 -70.0325 1.0000
then I use 'Imwarp' to transfer moving image to the fixed image. In my code it is,
nii=load_untouch_nii(['mypath image.nii' ]);
I = nii.img;
dii=nii.hdr.dime.pixdim(2:4);
Rfixed=imref3d(size(I),dii(2),dii(1),dii(3));
timg= imwarp(I, Rfixed, tform, 'OutputView', Rfixed);
'timg' is transfered image of source image.I checked it and it is working fine, but I need control points or displacement field of this transformation now. In another word, I need to know each voxel(3d pixel) moved to which position. If I know this I can draw vector field. In deformable image registartion methods such as NiftyReg package, control point command is provided to make it easy for users but I do not know how to do it in simple 3d affine in Matlab. Any help will be appreciated too much
回答1:
You can apply your geometric transform to a single point very easily.
You just need to have your point defined as p=[x;y;z;1]
and then obtain pt
by pt=p*tform;
pt=pt(1:3)./pt(4);
(search for homogeneous coordinates for explanation of this last division). This is what imwarp
does in the inside. It performs the said multiplication for each pixel p
.
To then obtain the displacement, you would need just to disp=pt-p;
. Note that the displacements are most likely not integer.
Note that in the field of deformable image registration, generally you will have a different tform
for each control point (that is why it is called deformable and not rigid)
EDIT: as @Ashish Uthama suggests in the comments, you can also do it with Matlab inbuilt function transformpointsforward()
. I will always be a promoter of "writing your own code" philosophy, specially the first time, so you do understand what are you actually doing.
http://uk.mathworks.com/help/images/ref/affine3d.transformpointsforward.html
来源:https://stackoverflow.com/questions/30240436/how-to-get-displacement-field-or-control-point-vector-when-we-have-tfrom