Clear Filters
Clear Filters

"imregform"+"imwarp" do not show the same result as "imregister"

6 views (last 30 days)
I have two images A (1500x1500), B (1002x1004). The respective image data should be coregistered.
[optimizer,metric] = imregconfig("multimodal");
optimizer.MaximumIterations = 300;
movingReg1 = imregister(A,B,"affine",optimizer,metric);
"imregister" does a fair job and results as expected in an image of dimentsions of B (1002x1004). But I need the transformation matrix to apply to a third image ( C). So I tried "imregtform" to get the transformation object and check with "imwarp" if it does the transformation similar to "imregister"
tform = imregtform(A,B,'affine',optimizer,metric);
movingReg2 = imwarp(A,tform);
The resultant image seems to have the right scaling rotation applied but is stuck in the top left corner and has dimensions (1630x1538). The optimizer and metric are the same as above.
How do I get the same results for both?
Thanks so much.
(Matlab 2022b)

Answers (1)

Manoj Mirge
Manoj Mirge on 22 Feb 2023
Hi Andre,
To get the same result image by using function imregister and by using (imregtform + imwarp), you need to use the additional OutputView name-value argument in the imwarp function.
In imwarp function you need to give the value of imref2d(size(B)) to the OutputView name in function argument, where B is the reference image.
OutputView specifies size and location of output image in the world coordinate system. It can be given value of an imref2d or imref3d spatial referencing image object. An imref2d object stores the relationship between the intrinsic coordinates anchored to the rows and columns of a 2-D image and the spatial location of the same row and column locations in a world coordinate system.
You can read more about how to use imregtform and imwarp here.
You can read more about OutputView Nave Value pair here.
You can read more about imref2d here.
In your case you want to transform image A by using reference image B. If you just add OutputView name vame-value pair to your imwarp function, you will get image movingReg2 which will be same as image movingReg1.
Below is the sample code for the same:
% You have two images A and B
[optimizer,metric] = imregconfig("multimodal");
optimizer.MaximumIterations = 300;
movingReg1 = imregister(A,B,"affine",optimizer,metric);
% Using imregtform and imwarp
tform = imregtform(A,B,'affine',optimizer,metric);
movingReg2 = imwarp(A,tform,"OutputView",imref2d(size(B));
%Now you will get same result in movingReg2 image
% You can confirm that by using imabsdiff function.
% Z = imabsdiff(X,Y) subtracts each element in array Y from the corresponding element in array X and returns the absolute difference in the corresponding element of the output array Z.
diff=imabsdiff(movingReg1,movingReg2);
%diff will be matrix of zeros. This shows that both image movingReg1 and movingReg2 are same.
You can read more about imabsdiff here.
Hope this will help.

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!