-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaddcircle.m
58 lines (46 loc) · 1.44 KB
/
addcircle.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
% ADDCIRCLE
%
% A circle generator for adding (drawing) weights into a Hough accumumator
% array.
%
% Usage: h = addcircle(h, c, radius, weight)
%
% Arguments:
% h - 2D accumulator array.
% c - [x,y] coords of centre of circle.
% radius - radius of the circle
% weight - optional weight of values to be added to the
% accumulator array (defaults to 1)
%
% Returns: h - Updated accumulator array.
% Peter Kovesi
% Department of Computer Science & Software Engineering
% The University of Western Australia
% April 2002
function h = addcircle(h, c, radius, weight)
[hr, hc] = size(h);
if nargin == 3
weight = 1;
end
% c and radius must be integers
if any(c-fix(c))
error('Circle centre must be in integer coordinates');
end
if radius-fix(radius)
error('Radius must be an integer');
end
x = 0:fix(radius/sqrt(2));
costheta = sqrt(1 - (x.^2 / radius^2));
y = round(radius*costheta);
% Now fill in the 8-way symmetric points on a circle given coords
% [px py] of a point on the circle.
px = c(2) + [x y y x -x -y -y -x];
py = c(1) + [y x -x -y -y -x x y];
% Cull points that are outside limits
validx = px>=1 & px<=hr;
validy = py>=1 & py<=hc;
valid = find(validx & validy);
px = px(valid);
py = py(valid);
ind = px+(py-1)*hr;
h(ind) = h(ind) + weight;