Noga
Noga

Reputation: 41

How to calculate new coordinates of a point In an image after registration?

Say I have the X-Y coordinates of a certain point in an image.

Then, I perform a non-deforming registration on this image using 'similarity' optimization.

Now I would like to calculate the new X-Y coordinates that correspond with the same point in the image (after registration).

I bet there should be a way to do so by using tform / the spatial referencing object / something similar...

Does anyone know how to do this?

Upvotes: 2

Views: 762

Answers (1)

Alex Taylor
Alex Taylor

Reputation: 1412

Given a rigid transformation that is represented in MATLAB as an affine2d object, you can calculate the new XY points that correspond to the location in the output space of the transformed image by calling the transformPointsForward method of affine2d.

For example:

fixed  = imread('cameraman.tif');
theta = 20;
S = 2.3;
tform = affine2d([S.*cosd(theta) -S.*sind(theta) 0; S.*sind(theta)     S.*cosd(theta) 0; 0 0 1]);
moving = imwarp(fixed,tform);
moving = moving + uint8(10*rand(size(moving)));
tformEstimate = imregcorr(moving,fixed);
[x_out,y_out] = transformPointsForward(tformEstimate,10,20)

Also, if you want to transform in the opposite direction (from the output space to the input space), you can similarly use the transformPointsInverse method.

[u_out,v_out] = transformPointsInverse(tformEstimate,x_out,y_out)

Upvotes: 2

Related Questions