bzr branch
http://suren.me/webbzr/normxcorr/trunk
1
by Suren A. Chilingaryan
Initial import |
1 |
%-------------------------------
|
2 |
% Function local_sum
|
|
3 |
%
|
|
4 |
function local_sum_A = dic_local_sum(A,m,n) |
|
5 |
||
6 |
% We thank Eli Horn for providing this code, used with his permission,
|
|
7 |
% to speed up the calculation of local sums. The algorithm depends on
|
|
8 |
% precomputing running sums as described in "Fast Normalized
|
|
9 |
% Cross-Correlation", by J. P. Lewis, Industrial Light & Magic.
|
|
10 |
% http://www.idiom.com/~zilla/Papers/nvisionInterface/nip.html
|
|
11 |
||
12 |
[mA,nA]=size(A); |
|
13 |
||
14 |
B = [zeros(m,nA+2*n-1); |
|
15 |
zeros(mA,n) A zeros(mA,n-1); |
|
16 |
zeros(m-1,nA+2*n-1)]; |
|
17 |
s = cumsum(B,1); |
|
18 |
c = s(1+m:end,:)-s(1:end-m,:); |
|
19 |
s = cumsum(c,2); |
|
20 |
local_sum_A = s(:,1+n:end)-s(:,1:end-n); |