Tune control point locations using cross-correlation
adjusts the position of moving control points,
movingPointsAdjusted = cpcorr(
with respect to fixed control points,
normalized cross-correlation between the moving image
and the fixed image
function returns the adjusted moving control points in
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. The position of the moving points is slightly offset from the position of the fixed points.
imshow(fixed) hold on plot(fixedPoints(:,1),fixedPoints(:,2),'xw') title('Fixed Image')
figure imshow(moving) hold on plot(movingPoints(:,1),movingPoints(:,2),'xw') title('Moving Image')
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.
movingPoints— Coordinates of control points in image to be transformed
Coordinates of control points in the image to be transformed, specified as an m-by-2 matrix. The two columns represent the x- and y-coordinates of the control points, respectively, in the intrinsic coordinate system of the image.
[127 93; 74 59]
fixedPoints— Coordinates of control points in reference image
Coordinates of control points in the reference image, specified as an p-by-2 matrix. The two columns represent the x- and y-coordinates of the control points, respectively, in the intrinsic coordinate system of the image.
[323 195; 269 161]
moving— Image to be registered
Image to be registered, specified as a numeric array.
fixed— Reference image in target orientation
Reference image in the target orientation, specified as a numeric array.
cpcorr cannot adjust a point if any of these conditions
points are too near the edge of either image
regions of images around points contain
region around a point in moving image has zero standard deviation
regions of images around points are poorly correlated
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.
backgroundPoolor accelerate code with Parallel Computing Toolbox™
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.