Reputation: 25
I'm new to Matlab and I'm trying to do a Control Point Registration using their guide: http://www.mathworks.com/help/images/point-mapping.html
It works fine until the 'fitgeotrans' function where I get an error that saying: 'Undefined function or variable 'input_points'.
I read the Matlab help and the previous "cpselect" function gives me two nX2 arrays with the coordinates which are saved (by the 'cpselect' function) in two array variables 'input_points' and 'base_points'. So, I really don't understand why the next function can't "See" them and considers them 'Undefined'.
My code is attached bellow. Thank you for your help.
function [Y] =EBL
ReferenceImg=imread('GFI.jpg'); %This is the fixed image
CroppedImg=imcrop(ReferenceImg); %Crop the image
close %close the imcrop window
ResizedIReferenceImg= imresize(CroppedImg,[1000 1000]); %re-size the fixed image
t=imagesc(ResizedIReferenceImg); %Set transparency of fixed image
set(t,'AlphaData',0.5);
hold on
I = imread('GF.bmp'); %This is the moving picture
MovingImg = imrotate(I,-5,'nearest','crop'); % Rotate the moving picture cw
ResizedMovingImg= imresize(MovingImg,[1000 1000]); %re-size the moving image
h=imagesc(ResizedMovingImg); %Set transparency of moving image
set(h,'AlphaData',0.6);
close
cpselect(ResizedMovingImg,ResizedIReferenceImg); %Alignment
tform = fitgeotrans(input_points,base_points,'NonreflectiveSimilarity');
Upvotes: 1
Views: 1450
Reputation: 7817
The problem is that MATLAB doesn't, by default, wait for you to be done before moving on from cpselect
. So it simply moves on from cpselect
to tform
before you have a chance to actually select any points, at which point input_points
doesn't yet exist. You have to set the Wait
parameter, and doing so also affects the outputs. With Wait
on, call cpselect
something like this:
[input_points,base_points] = cpselect(MovingImg,ReferenceImg,'Wait', true);
When calling cpselect
in this way, you will not have the "Export Points to Workspace" option. Instead, the selected points will be output into the variables input_points,base_points
when the cpselect
window is closed.
Upvotes: 3