How do I find the exact position of my input points on the image transformed by using the IMTRANSFORM function in the Image Processing Toolbox in MATLAB 7.11 (R2010b)?

2 views (last 30 days)
I have an image, which I transform using the IMTRANSFORM function. For example,
original_im = imread('cameraman.tif');
figure; imshow(original_im);
control_point = [70 66];
hold on
plot(control_point(1), control_point(2), 'b*')
base_points = [11 11; 41 71];
input_points = [14 44; 70 81];
T = cp2tform(input_points,base_points,'nonreflective similarity');
[new_im, xdata, ydata] = imtransform(original_im, T);
I would like to know if it's possible to determine "analytically" the exact position (pixel coordinates) of my control points on the transformed picture.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 28 Dec 2010
It is possible to "analytically" determine the position of your control points in the transformed image using the Image Processing Toolbox. To achieve this there are two essential steps:
1. Call IMTRANSFORM with XDATA and YDATA output (or input) arguments.
2. Apply TFORMFWD to the points you picked on your input image.
First compute the transformation T as shown below:
T = cp2tform(input_points,base_points,'nonreflective similarity');
Now you have a transformation, T, that will approximately map each input point to its corresponding base point. You can check its consistency with your data before you even transform the image (that is, see how good/bad the approximation is). To do this first compute the predicted points by using TFORMFWD as shown below:
predicted_destinations = tformfwd(T, input_points)
Then compare the predicted points to the base points to see how well the transformation performed. Ideally you'll see residuals that are smaller than one pixel. In many applications, residuals of several pixels will be acceptable. Based on the residuals you might decide that you need another type of transformation for a better fit.
Then, if you call IMTRANSFORM with only two input arguments
new_im = imtransform(original_im, T)
you're allowing IMTRANSFORM to apply an additional, unspecified, translation when computing "new_im". When you use this syntax, IMTRANSFORM automatically shifts the origin of your output image to make as much of the transformed image visible as possible. (If you are using IMTRANSFORM to do image registration, this syntax is not likely to give you the results you expect; you may want to set the "XData" and "YData" input parameters explicitly.)
Now, if you specify additional output arguments as shown below:
[new_im, xdata, ydata] = imtransform(original_im, T)
then the 'xdata' and 'ydata' outputs from IMTRANSFORM will describe exactly what translation was applied. Then, when displaying "new_im" with IMAGE or IMSHOW, you can use the additional parameter name-value pairs:
figure; imshow(new_im,'XData', xdata, 'YData', ydata);
to control the position of the image on the axes.
Then, compute and plot the predicted_destinations of the control points, as follows:
predicted_destinations = tformfwd(T, control_point);
hold on
plot(predicted_destinations(1), predicted_destinations(2), 'r*')

More Answers (0)

Products


Release

R14SP2

Community Treasure Hunt

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

Start Hunting!