-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathedgeMask.m
89 lines (61 loc) · 2.25 KB
/
edgeMask.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
function M = edgeMask(varargin)
% edgeMask returns mask for bad edges using the matchag field
%
% m1 = edgeMask(m0) where m0 is the matchtag array returns a binary mask of
% size(m0) designed to filter data bad edges using match point density
m = varargin{1};
%defaults
%2m
n =21; % data density kernel
Pmin=.8; % data density threshold for masking
Amin=1000; % minimum data cluster area
cf = 0.5; %boundary curvature factor (0= point boundary, 1 =conv hull)
crop=n;
%for 2m SETSM 2.xxxx
% n=101;
% Pmin=.99;
% %8m
% n =5; % data density kernel
% Pmin=.8; % data density threshold for masking
% Amin=250; % minimum data cluster area
% cf = 0.5; %boundary curvature factor (0= point boundary, 1 =conv hull)
% crop = n;
% parse inputs
for i = 2:2:length(varargin)
switch lower(varargin{i})
case 'n'
n=varargin{i+1};
case 'pmin'
Pmin=varargin{i+1};
case 'amin'
Amin=varargin{i+1};
case 'crop'
crop=varargin{i+1};
case 'cf'
cf=varargin{i+1};
case 'm0'
M0=varargin{i+1};
end
end
P = DataDensityMap(m,n); % data density map is the fraction of pixels in
% the kernel containing data points.
if exist('M0','var')
M=P>=Pmin | M0; % data density threshold for masking
else
M=P>=Pmin; % data density threshold for masking
end
if ~any(M(:)); return; end
M = imfill(M,'holes'); % fill interior holes since we're just looking for
% edges here.
M = bwareaopen(M, Amin); % get rid of isolated little clusters of data
if ~any(M(:)); return; end
B = bwboundaries(M, 8, 'noholes'); % find data coverage boundaries
B = cell2mat(B); % merge all the data clusters
%k = convhull(B(:,2),B(:,1)); % find outer data boundary - the convex hull
% gives the straight line trace of the outer
% edge.
k = boundary(B(:,2),B(:,1),cf); % find outer data boundary - this function
% is like convhull but allows for some
% inward "bending" to conform to the data.
M = poly2mask(B(k,2),B(k,1), size(m,1),size(m,2)); % build edge mask
M = imerode(M,ones(crop)); % apply crop