/normxcorr/trunk

To get this branch, use:
bzr branch http://suren.me/webbzr/normxcorr/trunk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
function xyinput = dic_cpcorr(CORRSIZE, PRECISION, OPTIMIZE, hwid, base, xyinput_in, input)
%   Copyright 1993-2004 The MathWorks, Inc.
%   $Revision: 1.16.4.4 $  $Date: 2004/10/20 17:54:13 $

ncp = size(xyinput_in,1);
xyinput = xyinput_in; % initialize adjusted control points matrix

normxcorr_hw(hwid, 3, xyinput_in(:,1), xyinput_in(:,2));
normxcorr_hw(hwid, 12, input)
new_xy = normxcorr_hw(hwid, 4);

for icp = 1:ncp
    corr_offset = new_xy(icp,:);
    input_fractional_offset = xyinput(icp,:) - round(xyinput(icp,:)*PRECISION)/PRECISION;
    xyinput(icp,:) = xyinput(icp,:) - input_fractional_offset - corr_offset + base(icp).base_fractional_offset;
end


%{
% Just for validation purposes
for icp=1:ncp
    norm_cross_corr = double(normxcorr_hw(hwid, 11, icp, input));

    subpixel = true;
    [xpeak, ypeak, amplitude] = findpeak(norm_cross_corr,subpixel);

    %THRESHOLD = 0.5;
    %if (amplitude < THRESHOLD) 
        % low correlation, unable to adjust
    %    continue
    %end
    
    % offset found by cross correlation
    corr_offset = [ (xpeak-3*CORRSIZE-1) (ypeak-3*CORRSIZE-1) ];

    res(icp,1) = corr_offset(1);
    res(icp,2) = corr_offset(2);

    % eliminate any big changes in control points
    ind = find(abs(corr_offset) > (CORRSIZE-1));
    if ~isempty(ind)
        % peak of norxcorr2 not well constrained, unable to adjust
        continue
    end

    input_fractional_offset = xyinput(icp,:) - round(xyinput(icp,:)*PRECISION)/PRECISION;
    
    % adjust control point
    %xyinput(icp,:) = xyinput(icp,:) - input_fractional_offset - corr_offset + base(icp).base_fractional_offset;
end

%o1=res(500:510,:)'
%n1=new_xy(500:510,:)'
%o2=res(800:810,:)'
%n2=new_xy(800:810,:)'

mydiff = abs(new_xy - res);
sum(mydiff)
max(mydiff)
%}