forked from sakjain92/16-720-FinalProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_ncc_matrix.m
More file actions
39 lines (28 loc) · 1.2 KB
/
get_ncc_matrix.m
File metadata and controls
39 lines (28 loc) · 1.2 KB
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
function [nccmatrix] = get_ncc_matrix(frame1, tframe)
% Finds the ncc for each point using it's neighbour hood
% Take a neighbour hood of 3*3
neigh = 3;
offset = (neigh - 1)/2;
ptframe = padarray(tframe, [offset offset], 'symmetric');
pframe1 = padarray(frame1, [offset offset], 'symmetric');
% Find the location of old points in padded array
[X Y] = meshgrid(1:size(tframe, 2), 1:size(tframe, 1));
pX = X + offset;
pY = Y + offset;
pLocs = sub2ind(size(ptframe), pY, pX);
% Find relative offsets in a neighbourhood
[nX,nY] = meshgrid(1:neigh,1:neigh);
inds = sub2ind(size(ptframe),nY,nX);
midEl = (neigh * neigh + 1)/2;
offsets = inds - inds(midEl);
offsets = reshape(offsets,1,numel(offsets));
all_Locs = repmat(pLocs(:),1,numel(offsets));
all_offsets = repmat(offsets,numel(pLocs),1);
patchLocs = all_Locs + all_offsets;
pointstframe = ptframe(patchLocs);
pointsframe1 = pframe1(patchLocs);
nccm = sum((pointsframe1 - repmat(mean(pointsframe1, 2), 1, numel(offsets))) .* (pointstframe - repmat(mean(pointstframe, 2), 1, numel(offsets))), 2) / numel(offsets);
nccm = nccm ./ std(pointsframe1, [], 2);
nccm = nccm ./ std(pointstframe, [], 2);
nccmatrix = reshape(nccm, size(tframe));
end