Products & Services Solutions Academia Support User Community Company

Learn more about Image Processing Toolbox   

Example: Performing Image Registration

Step 1: Read in Base and Unregistered Images

This example is intended to clarify the spatial relationship between the output image and the base image in image registration. The example illustrates use of the optional 'XData' and 'YData' input parameters and the optional xdata and ydata output values. To begin the example, read the base and unregistered images from sample data files that come with the Image Processing Toolbox software.

base = imread('westconcordorthophoto.png');
unregistered = imread('westconcordaerial.png');

Step 2: Display the Unregistered Image

Display the unregistered image.

iptsetpref('ImshowAxesVisible','on')
imshow(unregistered)
text(size(unregistered,2),size(unregistered,1)+30, ...
    'Image courtesy of mPower3/Emerge', ...
    'FontSize',7,'HorizontalAlignment','right');

Step 3: Create a TFORM Structure

Create a TFORM structure using preselected control points. Start by loading a MAT-file that contains preselected control points for the base and unregistered images.

load westconcordpoints
tform = cp2tform(input_points, base_points, 'projective');

Step 4: Transform the Unregistered Image

Use imtransform to perform the transformation necessary to register the unregistered image with the base image. This code uses the optional FillValues input parameter to specify a fill value (white). The white background will help when the base image is placed on the transformed image to check registration.

registered = imtransform(unregistered, tform,...
   'FillValues', 255);

Display the registered image.

figure; imshow(registered);
hold on

Notice two things: (1) the full content of the unregistered image is present, although spatially transformed, and (2) there are no blank rows or columns. Neither of these things is a coincidence. imtransform carefully "followed" the image data as it transformed, in order to include everything there is to see and nothing more.

Step 5: Overlay Base Image Over Registered Image

Overlay a semitransparent version of the base image over the registered image. Notice how the two images appear misregistered because the example assumes that the images are in the same spatial coordinate system. The next steps provide two ways to remedy this display problem.

h = imshow(base, gray(256));
set(h, 'AlphaData', 0.6)

Registered Image with Base Image Overlay

Step 6: Using XData and YData Input Parameters

One way to ensure that the registered image appears registered with the base image is to truncate the registered image by discarding any areas that would extrapolate beyond the extent of the base image. You use the 'XData' and 'YData' parameters to do this.

registered1 = imtransform(unregistered,tform,...
                          'FillValues', 255,...
                          'XData', [1 size(base,2)],...
                          'YData', [1 size(base,1)]);

Display the registered image, overlaying a semitransparent version of the base image for comparison. The registration is evident, but part of the unregistered image has been discarded. The next step provides another solution in which the entire registered image is visible.

figure; imshow(registered1)
hold on
h = imshow(base, gray(256));
set(h, 'AlphaData', 0.6)

Registered Image Truncated with Base Image Overlay

Step 7: Using xdata and ydata Output Values

Another approach is to compute the full extent of the registered image and use the optional imtransform syntax that returns the x- and y-coordinates that indicate the transformed image's position relative to the base image's pixel coordinates.

[registered2 xdata ydata] = imtransform(unregistered, tform,...
                                        'FillValues', 255);

Display the registered image. Overlay a semi-transparent version of the base image for comparison.

figure; imshow(registered2, 'XData', xdata, 'YData', ydata)
hold on
h = imshow(base, gray(256));
set(h, 'AlphaData', 0.6)

Registered Image with Base Image Overlay

Adjust the axes to include the full base image. In this case, notice how the registration is evident and the full extent of both images is visible as well.

ylim = get(gca, 'YLim');
set(gca, 'YLim', [0.5 ylim(2)])

Registered Image with Base Image Overlay and Adjusted Axes

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS