Skip to content

Commit

Permalink
New option for orientation correlation
Browse files Browse the repository at this point in the history
Added Orientation Correlation method
  • Loading branch information
Aslak Grinsted committed Sep 19, 2016
1 parent c2e9077 commit d4ca64c
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions templatematch.m
Expand Up @@ -20,7 +20,10 @@
% ShowProgress: Boolean or cell-array of strings.
% true (default) is used for a text progress bar.
% A cell of strings is used to name the A & B images in a progress figure.
% Method: 'NCC'(default), 'NORMXCORR2' or 'PC' (normalized cross correlation or phase correlation)
% Method: 'NCC' (Default: Normalized Cross Correlation)
% 'CCF' (Cross correlation function)
% 'OC' (Orientation Correlation)
% 'PC' (experimental - phase correlation)
%
% * The template/search height is assumed to be the same as corresponding
% widths if not explicitly specified.
Expand Down Expand Up @@ -76,6 +79,7 @@
p.addParameter('ShowProgress',true);
p.addParameter('Method','NCC',@ischar);
p.addParameter('SuperSample',1);
p.addParameter('Prior',@(pu,pv,dx,dy)1); %TODO ---

p.parse(varargin{:});
R=p.Results;
Expand Down Expand Up @@ -143,6 +147,13 @@
if ~isfloat(A),A=im2float(A); end
if ~isfloat(B),B=im2float(B); end
matchfun=@myNCC;
case {'OC'}
if ~isfloat(A),A=im2float(A); end
if ~isfloat(B),B=im2float(B); end
gf=[1 0 -1]; %gf=[1 0;0 -1]; gf=[1 -1];
ofilter=@(A)exp(1i*atan2(imfilter(A,gf,'replicate'),imfilter(A,rot90(gf),'replicate')));
A=ofilter(A);B=ofilter(B);
matchfun=@CCF;
case {'CCF'}
if ~isfloat(A),A=im2float(A); end
if ~isfloat(B),B=im2float(B); end
Expand All @@ -153,6 +164,7 @@
error('imgraft:inputerror','unknown Method: %s',R.Method)
end


if ~isreal(B)
B=conj(B); %TODO: if you pass it orientation angles.
end
Expand All @@ -173,9 +185,13 @@

%INITIALIZE PROGRESS FIGURE....
if ~isempty(R.ShowProgress)

if islogical(R.ShowProgress)
progressmsg='';
else
if (~isreal(A))||(~isreal(B))
error('imgraft:inputerror','Progress figure is not compatible with complex input images / orientation correlation.')
end
fh=figure;
set(fh,'name','Templatematch progress','NumberTitle','off','renderer','opengl')
hax=axes('pos',[0 0.01 0.5 0.95]);
Expand Down Expand Up @@ -256,9 +272,10 @@
end



AA=resizefun(mean(AA,3),R.SuperSample); %TODO: improve edge effects of super sampling. (need 2 extra pixels for cubic)
BB=resizefun(mean(BB,3),R.SuperSample);
if R.SuperSample~=1
AA=resizefun(AA,R.SuperSample); %TODO: improve edge effects of super sampling. (need 2 extra pixels for cubic)
BB=resizefun(BB,R.SuperSample);
end

[C,uu,vv]=matchfun(AA,BB);
%TODO: allow for using max(C.*prior(uu,vv))
Expand Down

0 comments on commit d4ca64c

Please sign in to comment.