forked from petercorke/RVC3-MATLAB
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkcircle.m
More file actions
44 lines (37 loc) · 1010 Bytes
/
Copy pathkcircle.m
File metadata and controls
44 lines (37 loc) · 1010 Bytes
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
%KCIRCLE Circular structuring element
%
% K = KCIRCLE(R) is a square matrix (WxW) where W=2R+1 of zeros with a
% maximal centered circular region of radius R pixels set to one.
%
% K = KCIRCLE(R,W) as above but the dimension of the kernel is explicitly
% specified.
%
% Notes::
% - If R is a 2-element vector the result is an annulus of ones, and
% the two numbers are interpretted as inner and outer radii.
%
% See also ONES, KTRIANGLE, IMORPH.
% Copyright 2022-2023 Peter Corke, Witold Jachimczyk, Remo Pillat
function s = kcircle(r, w)
if ~isscalar(r)
rmax = max(r(:));
rmin = min(r(:));
else
rmax = r;
end
if nargin == 2
w = w*2 + 1;
elseif nargin == 1
w = 2*rmax+1;
end
s = zeros(w,w);
c = ceil(w/2);
if ~isscalar(r)
s = kcircle(rmax,w) - kcircle(rmin, w);
else
[x,y] = imeshgrid(s);
x = x - c;
y = y - c;
l = find(round(x.^2 + y.^2 - r^2) <= 0);
s(l) = 1;
end