How can I display registered images on top of one another?
5 views (last 30 days)
Show older comments
MathWorks Support Team
on 27 Jun 2009
Edited: MathWorks Support Team
on 17 Oct 2017
I have registered one image to another using IMTRANSFORM. I would like to display one image on top of the other. How can I specify the spatial location of IMTRANSFORM's output image so that the images can be displayed in one axes, and they will be aligned with one another?
Here is the code that I am attempting to use:
% Load the unregistered image, and make it grayscale.
unreg = imread('westconcordaerial.png');
unreg = rgb2gray(unreg);
% Load the registered image.
base = imread('westconcordorthophoto.png');
% Display the images.
figure, imshow(base), title('Base image');
figure, imshow(unreg), title('Unregistered image');
% Load the control points, construct the transform, and
% apply it to the unregistered image..
load westconcordpoints
tform = cp2tform(input_points, base_points, 'projective');
[registered] = imtransform(unreg, tform, 'Fill', 255);
% Display the combined figure.
figure, imshow(registered);
hold on
h = imshow(base);
set(h, 'AlphaData', 0.5);
title('Registered+Base image');
Accepted Answer
MathWorks Support Team
on 17 Oct 2017
This enhancement has been incorporated in Release 14 Service Pack 2 (R14SP2). For previous product releases, please read below for any possible workarounds:
The reason that the images are not aligned is because the x and y data of the images do not correspond with each other. In other words, the images do not share a common spatial coordinate system.
To correct this, you must explicitly specify the x and y coordinates of the images. The following example shows how to specify these values when you apply the transformation using IMTRANSFORM.
% Construct the transform.
tform = cp2tform(input_points, base_points, 'projective');
% Apply the transform, using the IMTRANSFORM syntax that
% returns the x and y values.
[registered, xdata, ydata] = imtransform(unreg, tform, 'Fill', 255);
% Display the combined figure, specifying the x and y coordinates.
figure, imshow(registered, 'XData', xdata, 'YData', ydata);
hold on
h = imshow(base);
set(h, 'AlphaData', 0.5);
title('Registered+Base image');
0 Comments
More Answers (0)
See Also
Categories
Find more on Read, Write, and Modify Image in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!