/normxcorr/trunk

To get this branch, use:
bzr branch http://suren.me/webbzr/normxcorr/trunk

« back to all changes in this revision

Viewing changes to dic_cpcorr3.m

  • Committer: Suren A. Chilingaryan
  • Date: 2009-12-06 12:27:00 UTC
  • Revision ID: csa@dside.dyndns.org-20091206122700-88vy44g7b0bn1fi3
FindPeak optimization

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function xyinput = dic_cpcorr(CORRSIZE, PRECISION, OPTIMIZE, 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 $
 
4
 
 
5
ncp = size(xyinput_in,1);
 
6
xyinput = xyinput_in; % initialize adjusted control points matrix
 
7
 
 
8
normxcorr_hw(hwid, 3, xyinput_in(:,1), xyinput_in(:,2));
 
9
normxcorr_hw(hwid, 12, input)
 
10
new_xy = normxcorr_hw(hwid, 4);
 
11
 
 
12
for icp = 1:ncp
 
13
    corr_offset = new_xy(icp,:);
 
14
    input_fractional_offset = xyinput(icp,:) - round(xyinput(icp,:)*PRECISION)/PRECISION;
 
15
    xyinput(icp,:) = xyinput(icp,:) - input_fractional_offset - corr_offset + base(icp).base_fractional_offset;
 
16
end
 
17
 
 
18
 
 
19
%{
 
20
% Just for validation purposes
 
21
for icp=1:ncp
 
22
    norm_cross_corr = double(normxcorr_hw(hwid, 11, icp, input));
 
23
 
 
24
    subpixel = true;
 
25
    [xpeak, ypeak, amplitude] = findpeak(norm_cross_corr,subpixel);
 
26
 
 
27
    %THRESHOLD = 0.5;
 
28
    %if (amplitude < THRESHOLD) 
 
29
        % low correlation, unable to adjust
 
30
    %    continue
 
31
    %end
 
32
    
 
33
    % offset found by cross correlation
 
34
    corr_offset = [ (xpeak-3*CORRSIZE-1) (ypeak-3*CORRSIZE-1) ];
 
35
 
 
36
    res(icp,1) = corr_offset(1);
 
37
    res(icp,2) = corr_offset(2);
 
38
 
 
39
    % eliminate any big changes in control points
 
40
    ind = find(abs(corr_offset) > (CORRSIZE-1));
 
41
    if ~isempty(ind)
 
42
        % peak of norxcorr2 not well constrained, unable to adjust
 
43
        continue
 
44
    end
 
45
 
 
46
    input_fractional_offset = xyinput(icp,:) - round(xyinput(icp,:)*PRECISION)/PRECISION;
 
47
    
 
48
    % adjust control point
 
49
    %xyinput(icp,:) = xyinput(icp,:) - input_fractional_offset - corr_offset + base(icp).base_fractional_offset;
 
50
end
 
51
 
 
52
%o1=res(500:510,:)'
 
53
%n1=new_xy(500:510,:)'
 
54
%o2=res(800:810,:)'
 
55
%n2=new_xy(800:810,:)'
 
56
 
 
57
mydiff = abs(new_xy - res);
 
58
sum(mydiff)
 
59
max(mydiff)
 
60
%}