-
Notifications
You must be signed in to change notification settings - Fork 110
/
createmask.m
94 lines (76 loc) · 1.54 KB
/
createmask.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
function MASK = createmask(DEM,usehillshade)
%CREATEMASK create a binary mask using polygon mapping
%
% Syntax
%
% MASK = createmask(DEM)
% MASK = createmask(DEM,usehillshade)
%
% Description
%
% createmask is an interactive tool to create a mask based on an
% interactively mapped polygon.
%
% Input arguments
%
% DEM GRIDobj
% usehillshade use hillshade as background image ({false} or true)
%
% Output arguments
%
% MASK GRIDobj with logical mask
%
%
% See also: imroi, GRIDobj
%
% Author: Wolfgang Schwanghart (w.schwanghart[at]geo.uni-potsdam.de)
% Date: 17. August, 2017
if nargin == 1
usehillshade = false;
end
figure
if usehillshade
imageschs(DEM);
else
imagesc(DEM);
end
title('Create polygon');
usedrawpolygon = ~verLessThan('matlab','9.5');
if usedrawpolygon
ext = getextent(DEM);
h = drawpolygon('DrawingArea',...
[ext(1) ext(3) ext(2)-ext(1) ext(4)-ext(3)]);
pos = customWait(h);
else
h = impoly;
pos = wait(h);
end
MASK = DEM;
MASK.name = 'mask';
MASK.Z = createMask(h);
if usedrawpolygon
pos = h.Position;
else
pos = getPosition(h);
end
delete(h);
hold on
plot(pos([1:end 1],1),pos([1:end 1],2));
hold off
title('done');
end
function pos = customWait(hROI)
% Listen for mouse clicks on the ROI
l = addlistener(hROI,'ROIClicked',@clickCallback);
% Block program execution
uiwait;
% Remove listener
delete(l);
% Return the current position
pos = hROI.Position;
end
function clickCallback(~,evt)
if strcmp(evt.SelectionType,'double')
uiresume;
end
end