cpcorr

Tune control point locations using cross-correlation

Description

example

movingPointsAdjusted = cpcorr(movingPoints,fixedPoints,moving,fixed) uses normalized cross-correlation to adjust each pair of control points specified in movingPoints and fixedPoints. moving and fixed are images. cpcorr returns the adjusted control points in movingPointsAdjusted.

Note

The moving and fixed images must have the same scale for cpcorr to be effective. If cpcorr cannot correlate a pair of control points, movingPointsAdjusted contains the same coordinates as movingPoints for that pair.

Examples

collapse all

Read two images into the workspace.

moving = imread('onion.png');
fixed = imread('peppers.png');

Define sets of control points for both images.

movingPoints = [118 42;99 87];
fixedPoints = [190 114;171 165];

Display the images, and display the control points in white.

figure; imshow(fixed)
hold on
plot(fixedPoints(:,1),fixedPoints(:,2),'xw') 
title('fixed')

figure; imshow(moving)
hold on
plot(movingPoints(:,1),movingPoints(:,2),'xw') 
title('moving')

Observe the slight errors in the position of the moving points.

Adjust the moving control points using cross correlation.

movingPointsAdjusted = cpcorr(movingPoints,fixedPoints,...
                              moving(:,:,1),fixed(:,:,1))
movingPointsAdjusted = 2×2

  115.9000   39.1000
   97.0000   89.9000

Display the adjusted moving points in yellow. Compared to the original moving points (in white), the adjusted points more closely match the positions of the fixed points.

plot(movingPointsAdjusted(:,1),movingPointsAdjusted(:,2),'xy')      

Input Arguments

collapse all

Coordinates of control points in the image to be transformed, specified as an M-by-2 double matrix.

Example: movingPoints = [127 93; 74 59];

Data Types: double

Coordinates of control points in the reference image, specified as an M-by-2 double matrix.

Example: fixedPoints = [323 195; 269 161];

Data Types: double

Image to be registered, specified as a numeric array of finite values.

Reference image in the target orientation, specified as a numeric array of finite values.

Output Arguments

collapse all

Adjusted coordinates of control points in the image to be transformed, returned as a double matrix the same size as movingPoints.

Tips

cpcorr cannot adjust a point if any of the following occur:

  • points are too near the edge of either image

  • regions of images around points contain Inf or NaN

  • region around a point in moving image has zero standard deviation

  • regions of images around points are poorly correlated

Algorithms

cpcorr only moves the position of a control point by up to four pixels. Adjusted coordinates are accurate up to one-tenth of a pixel. cpcorr is designed to get subpixel accuracy from the image content and coarse control point selection.

Introduced before R2006a