forked from davidstutz/nyu-depth-v2-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseg2bdry.m
36 lines (27 loc) · 985 Bytes
/
seg2bdry.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
function [bdry] = seg2bdry(seg, fmt)
if nargin < 2
fmt = 'doubleSize';
end;
if ~strcmp(fmt,'imageSize') && ~strcmp(fmt,'doubleSize')
error('possible values for fmt are: imageSize and doubleSize');
end;
[tx, ty, nch] = size(seg);
if nch ~= 1
error('seg must be a scalar image');
end;
bdry = zeros(2*tx+1, 2*ty+1);
edgels_v = ( seg(1:end-1, :) ~= seg(2:end, :) );
edgels_v(end+1, :) = 0;
edgels_h = ( seg(:, 1:end-1) ~= seg(:, 2:end) );
edgels_h(:, end+1) = 0;
bdry(3:2:end, 2:2:end) = edgels_v;
bdry(2:2:end, 3:2:end) = edgels_h;
bdry(3:2:end-1, 3:2:end-1)= max ( max(edgels_h(1:end-1, 1:end-1), edgels_h(2:end, 1:end-1)), max(edgels_v(1:end-1,1:end-1), edgels_v(1:end-1,2:end)) );
bdry(1, :) = bdry(2, :);
bdry(:, 1) = bdry(:, 2);
bdry(end, :) = bdry(end-1, :);
bdry(:, end) = bdry(:, end-1);
if strcmp(fmt,'imageSize')
bdry = bdry(3:2:end, 3:2:end);
end;
end