forked from xiaodongyang/SNV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompNormals.m
60 lines (46 loc) · 2.04 KB
/
compNormals.m
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 compNormals(info)
for i = 1:info.ncls
idxcls = sprintf('a%02d', i);
for j = 1:info.nsbj
idxsbj = sprintf('s%02d', j);
for k = 1:info.nemp
idxemp = sprintf('e%02d', k);
disp(['computing normals of video: ', idxcls, '_', idxsbj, '_', idxemp, ' ......']);
% read depth sequences from a binary file
vidName = [info.vidpath, '\', idxcls, '_', idxsbj, '_', idxemp, '_sdepth.bin'];
depth = readDepthBin(vidName);
% some missed videos
if isempty(depth)
continue;
end
% compute derivatives of depth sequence
[nrows, ncols, nfrms] = size(depth);
dx = zeros(nrows, ncols, nfrms - 1);
dy = zeros(nrows, ncols, nfrms - 1);
dt = zeros(nrows, ncols, nfrms - 1);
for f = 1:nfrms-1
% smooth
frame1 = medfilt2(depth(:, :, f), [5, 5]);
frame2 = medfilt2(depth(:, :, f + 1), [5, 5]);
% derivatives along x/y/t
[dx(:, :, f), dy(:, :, f)] = gradient(frame1);
dt(:, :, f) = frame2 - frame1;
% normalize
reg = sqrt(dx(:, :, f).^2 + dy(:, :, f).^2 + dt(:, :, f).^2);
dx(:, :, f) = dx(:, :, f) ./ reg;
dy(:, :, f) = dy(:, :, f) ./ reg;
dt(:, :, f) = dt(:, :, f) ./ reg;
dx(isinf(dx)) = 0; dx(isnan(dx)) = 0;
dy(isinf(dy)) = 0; dy(isnan(dy)) = 0;
dt(isinf(dt)) = 0; dt(isnan(dt)) = 0;
end
% to mask cloud points belonging to human body
masks = logical(depth);
masks(:, :, end) = [];
% save normals and masks
normalName = [info.normpath, '\', idxcls, '_', idxsbj, '_', idxemp, '_norm.mat'];
save(normalName, 'dx', 'dy', 'dt', 'masks');
end
end
end
end