-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathellipseRoi.m
45 lines (38 loc) · 866 Bytes
/
ellipseRoi.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
function [in, h] = ellipseRoi(img, varargin)
%
% Select elliptical ROI from an image
% No image, No confirmation.
%
% output in : 2-D logical array
% Let's make logical matrix which indicates whether each pixel is inside or
% outside. Then, reshape!
% nVarargs = numel(varargin);
% if nVarargs == 1
%figure('position', [185, 400, 840, 700])
%img = varargin{1};
%end
%myshow(img);
%
h = imellipse;
if isempty(h)
error('ellipseRoi: ROI is not selected');
end
pos = getPosition(h); pos = double(pos);
%
xmin = pos(1);
ymin = pos(2);
width = pos(3);
height = pos(4);
a = width/2;
b = height/2;
x0 = xmin + a;
y0 = ymin + b;
[row, col] = size(img);
% ellipse mask
distX = (1:col) - x0;
distY = (1:row) - y0;
[x, y] = meshgrid(distX, distY);
in = ((x/a).^2+(y/b).^2) <= 1;
% confirm the area of logical area (in)
% C = merge(img, in); imshow(C);
end