Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

cpselect

Control Point Selection tool

Syntax

cpselect(moving,fixed)
cpselect(moving,fixed,cpstruct_in)
cpselect(moving,fixed,initialMovingPoints,initialFixedPoints)
h = cpselect(___)
h = cpselect(___,'Wait',false)
[selectedMovingPoints,selectedFixedPoints] = cpselect(___,'Wait',true)

Description

example

cpselect(moving,fixed) starts the Control Point Selection Tool, a user interface that enables you to select control points in two related images. moving is the image to be warped, which brings it into the coordinate system of the fixed image. moving and fixed can be either variables that contain grayscale, truecolor, or binary images, or the names of files containing these images. The Control Point Selection Tool returns the control points in a cpstruct structure.

cpselect(moving,fixed,cpstruct_in) starts cpselect with an initial set of control points that are stored in cpstruct_in. This syntax allows you to restart cpselect with the state of control points, including unpaired and predicted control points, previously saved in cpstruct_in.

example

cpselect(moving,fixed,initialMovingPoints,initialFixedPoints) starts cpselect with an initial set of valid control point pairs. initialMovingPoints and initialFixedPoints are m-by-2 matrices that store moving and fixed control point coordinates, respectively. The two columns represent the x- and y-coordinates of the control points.

h = cpselect(___) returns a handle h to the Control Point Selection tool. You can use the close(h) syntax to close the tool from the command line.

h = cpselect(___,'Wait',false) returns a handle h to the Control Point Selection tool. You can use the close(h) syntax to close the tool from the command line. In contrast to setting 'Wait' as true, this syntax lets you run cpselect at the same time as you run other programs in MATLAB®.

example

[selectedMovingPoints,selectedFixedPoints] = cpselect(___,'Wait',true) takes control of the MATLAB command line until you finish selecting control points. cpselect returns valid selected pairs of points. selectedMovingPoints and selectedFixedPoints are p-by-2 matrices that store the coordinates in the moving and fixed images, respectively. The two columns represent the x- and y-coordinates of the selected control points.

Examples

collapse all

Call cpselect , specifying the names of the image you want to register and the reference image. This example uses the optional syntax that returns a handle to the tool that is created so that you can close the tool programmatically.

h  = cpselect('westconcordaerial.png','westconcordorthophoto.png');

Close the tool.

close(h)

Create a sample reference image.

I = checkerboard;

Create a copy of the sample image, rotating it to create a sample image that needs registering.

J = imrotate(I,30);

Specify two sets of control points for the fixed and moving images.

fixedPoints = [11 11; 41 71];
movingPoints = [14 44; 70 81];

Open the Control Point Selection Tool, specifying the sample fixed and moving images and the two sets of saved control points.

cpselect(J,I,movingPoints,fixedPoints);

When the tool opens, you are prompted to save the control points.

Read an aerial photo and an orthophoto into the workspace and display them.

aerial = imread('westconcordaerial.png');
figure, imshow(aerial)
ortho = imread('westconcordorthophoto.png');
figure, imshow(ortho)

Load some points that have already been picked.

load westconcordpoints

Open the Control Point Selection tool, specifying the two images and the preselected points. Use the 'Wait' parameter to make cpselect wait for you to pick some more points.

[aerial_points,ortho_points] = ...
       cpselect(aerial,'westconcordorthophoto.png',...
                movingPoints,fixedPoints,...
                'Wait',true);

When control returns to the command line, perform the registration. First use fitgeotrans to estimate the geometric transformation required to bring the moving image into alignment with the fixed image. You specify the control points you selected and the type of transformation you want. Next use imwarp to perform the transformation. Finally, display the transformed image over the original orthophoto to see how well the registration succeeded.

t_concord = fitgeotrans(aerial_points,ortho_points,'projective');
ortho_ref = imref2d(size(ortho)); %relate intrinsic and world coordinates
aerial_registered = imwarp(aerial,t_concord,'OutputView',ortho_ref);
figure, imshowpair(aerial_registered,ortho,'blend')

Input Arguments

collapse all

Input image to be aligned, specified as a grayscale, truecolor, or binary image, or a character vector. A grayscale image can be uint8, uint16, int16, single, or double. A truecolor image can be uint8, uint16, single, or double. A binary image is of class logical. If moving is a character vector, it must identify files containing these same types of images.

Data Types: single | double | int16 | uint8 | uint16 | logical

Reference image, specified as a grayscale, truecolor, or binary image. A grayscale image can be uint8, uint16, int16, single, or double. A truecolor image can be uint8, uint16, single, or double. A binary image is of class logical. If fixed is a character vector, it must identify files containing these same types of images.

Data Types: single | double | int16 | uint8 | uint16 | logical

Preselected control points, specified as a structure (cpstruct). cpstruct_in contains information about x- and y-coordinates of all control points in the moving and fixed images, including unpaired and predicted control points. cpstruct_in also contains indexing information that allows the Control Point Selection tool to restore the state of the control points.

Create a cpstruct by exporting points from the Control Point Selection tool, described in Export Control Points to the Workspace.

Data Types: struct

Preselected control points on the moving image, specified as an m-by-2 numeric array. The two columns represent the x- and y-coordinates of the control points.

Data Types: double

Preselected control points on the fixed image, specified as an m-by-2 numeric array. The two columns represent the x- and y-coordinates of the control points.

Data Types: double

Output Arguments

collapse all

Control Point Selection tool, returned as a handle.

Selected control points on the moving image, specified as a p-by-2 numeric array. The two columns represent the x- and y-coordinates of the control points.

Data Types: double

Selected control points on the fixed image, specified as a p-by-2 numeric array. The two columns represent the x- and y-coordinates of the control points.

Data Types: double

Tips

  • When calling cpselect in a script, specify the 'Wait' option as true. The 'Wait' option causes cpselect to block the MATLAB command line until control points have been selected and returned. If you do not use the 'Wait' option, cpselect returns control immediately and your script continues without allowing time for control point selection. Additionally, without the 'Wait' option, cpselect does not return the control points as return values.

Algorithms

cpselect uses the following general procedure for control-point prediction.

  1. Find all valid pairs of control points.

  2. Infer a spatial transformation between moving and fixed control points using method that depends on the number of valid pairs, as follows:

    2 pairs

    Nonreflective similarity

    3 pairs

    Affine

    4 or more pairs

    Projective

  3. Apply spatial transformation to the new point. This transformation generates the predicted point.

  4. Display predicted point.

Introduced before R2006a

Was this topic helpful?