-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdrawContour.m
More file actions
77 lines (65 loc) · 1.85 KB
/
Copy pathdrawContour.m
File metadata and controls
77 lines (65 loc) · 1.85 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
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
function contour = drawContour( img, varargin )
% contour = drawContour( img )
%
% displays figure to the screen and lets user create a contour
% Type 'h' for help
%
% Inputs:
% img - 2D array representing the grayscale image or 3D array
% representing the color image (third dimension has size 3)
%
% Outputs:
% contour - 2D array of size N x 2 where N is the number of contour
% points
%
% Written by Jolie Wang - Copyright 2021
%
% https://github.com/ndwork/dworkLib.git
%
% This software is offered under the GNU General Public License 3.0. It
% is offered without any warranty expressed or implied, including the
% implied warranties of merchantability or fitness for a particular
% purpose.
if nargin < 1
disp( 'Usage: contour = drawContour( img )' );
contour = [];
return;
end
p = inputParser;
p.addOptional( 'scale', 1, @isnumeric );
p.parse( varargin{:} );
scale = p.Results.scale;
figure; imshowscale( img, scale );
hold on; grid on;
contour = [];
while true
title( 'type h for help' );
try
[y,x,button] = ginput(1);
zoom out;
catch
button = [];
end
if numel( button ) == 0
% Figure was closed before key was pressed
break;
elseif button == 'h'
disp( 'Left click with mouse to select a contour point.');
disp( 'h for this help' );
disp( 'q to quit the application' );
disp( 'z to zoom in and out of the image' );
elseif button == 'q'
close( gcf );
break;
elseif button == 'z'
zoom on;
title( 'Hit any key to end zoom' );
pause(); zoom off;
else
contour = [ contour; [ y x ]; ]; %#ok<AGROW>
plot( contour(:,1), contour(:,2), 'yx' );
plot( contour(:,1), contour(:,2), 'y' );
end
end
if scale ~= 1, contour = contour / scale; end
end