forked from palmerc/Hough
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHoughPoints.m
49 lines (43 loc) · 1.43 KB
/
HoughPoints.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
function [ Hough, theta_range, rho_range ] = HoughPoints(varargin)
%HOUGHCLP performs the Hough transform in a straightforward way.
%
[I, points] = ParseInputs(varargin{:});
[rows, cols] = size(I);
[Hough, theta_maximum, theta_range, rho_maximum, rho_range] = HoughMatrix(rows, cols);
for point_index = 1:size(points, 2)
point = points(:,point_index);
row = point(1);
col = point(2);
if I(row, col) > 0
x = col - 1;
y = row - 1;
for theta = theta_range
rho = round((x * cosd(theta)) + (y * sind(theta)));
rho_index = rho + rho_maximum + 1;
theta_index = theta + theta_maximum + 1;
Hough(rho_index, theta_index) = Hough(rho_index, theta_index) + 1;
end
end
end
end
%% ParseInputs - copied out of MatLab
function [I, points] = ParseInputs(varargin)
narginchk(1,2);
% Check I
I = varargin{1};
validateattributes(I, {'logical', 'numeric'}, {'2d', 'real', 'nonsparse'}, ...
mfilename, 'I', 1);
if nargin > 1
points = varargin{2};
else
[rows, cols] = size(I);
points = zeros(1, 2, rows * cols);
index = 1;
for row = 1:rows
for col = 1:cols
points(:,:,index) = [row, col];
index = index + 1;
end
end
end
end