1
function xyinput = dic_cpcorr(CORRSIZE, PRECISION, hwid, base, xyinput_in, input)
2
% Copyright 1993-2004 The MathWorks, Inc.
3
% $Revision: 1.16.4.4 $ $Date: 2004/10/20 17:54:13 $
5
%input = double(input);
7
if any(xyinput_in(:)<0.5) || any(xyinput_in(:,1)>size(input,2)+0.5) || ...
8
any(xyinput_in(:,2)>size(input,1)+0.5)
9
msg = sprintf('In function %s, Control Points must be in pixel coordinates.',mfilename);
10
eid = sprintf('Images:%s:cpPointsMustBeInPixCoord',mfilename);
15
% get all rectangle coordinates
16
rects_input = dic_calc_rects(xyinput_in, CORRSIZE, input);
18
ncp = size(xyinput_in,1);
20
xyinput = xyinput_in; % initialize adjusted control points matrix
25
% baned by base image (Nan, Inf, Near to edge, ...)
29
if isequal(rects_input(icp,3:4),[0 0])
30
% near edge, unable to adjust
34
sub_input = imcrop(input,rects_input(icp,:));
36
inputsize = size(sub_input);
39
if any(~isfinite(sub_input(:)))
40
% NaN or Inf, unable to adjust
44
sum_T = sum(sub_input(:));
45
denom_T = std(sub_input(:));
47
% check that template rectangle sub_input has nonzero std
49
% zero standard deviation of template image, unable to adjust
53
norm_cross_corr = double(normxcorr_hw(hwid, 11, icp, rot90(sub_input,2), sum_T, denom_T));
55
% get subpixel resolution from cross correlation
57
[xpeak, ypeak, amplitude] = findpeak(norm_cross_corr,subpixel);
59
% eliminate any poor correlations
61
if (amplitude < THRESHOLD)
62
% low correlation, unable to adjust
66
% offset found by cross correlation
67
corr_offset = [ (xpeak-inputsize(2)-CORRSIZE) (ypeak-inputsize(1)-CORRSIZE) ];
70
% eliminate any big changes in control points
71
ind = find(abs(corr_offset) > (CORRSIZE-1));
73
% peak of norxcorr2 not well constrained, unable to adjust
77
input_fractional_offset = xyinput(icp,:) - round(xyinput(icp,:)*PRECISION)/PRECISION;
79
% adjust control point
80
xyinput(icp,:) = xyinput(icp,:) - input_fractional_offset - corr_offset + base(icp).base_fractional_offset;