-
Notifications
You must be signed in to change notification settings - Fork 1
/
findcircle.m
76 lines (59 loc) · 2.27 KB
/
findcircle.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
% findcircle - returns the coordinates of a circle in an image using the Hough transform
% and Canny edge detection to create the edge map.
%
% Usage:
% [row, col, r] = findcircle(image,lradius,uradius,scaling, sigma, hithres, lowthres, vert, horz)
%
% Arguments:
% image - the image in which to find circles
% lradius - lower radius to search for
% uradius - upper radius to search for
% scaling - scaling factor for speeding up the
% Hough transform
% sigma - amount of Gaussian smoothing to
% apply for creating edge map.
% hithres - threshold for creating edge map
% lowthres - threshold for connected edges
% vert - vertical edge contribution (0-1)
% horz - horizontal edge contribution (0-1)
%
% Output:
% circleiris - centre coordinates and radius
% of the detected iris boundary
% circlepupil - centre coordinates and radius
% of the detected pupil boundary
% imagewithnoise - original eye image, but with
% location of noise marked with
% NaN values
%
% Author:
% Libor Masek
% masekl01@csse.uwa.edu.au
% School of Computer Science & Software Engineering
% The University of Western Australia
% November 2003
function [row, col, r] = findcircle(image,lradius,uradius,scaling, sigma, hithres, lowthres, vert, horz)
lradsc = round(lradius*scaling);
uradsc = round(uradius*scaling);
rd = round(uradius*scaling - lradius*scaling);
% generate the edge image
[I2 or] = canny(image, sigma, scaling, vert, horz);
I3 = adjgamma(I2, 1.9);
I4 = nonmaxsup(I3, or, 1.5);
edgeimage = hysthresh(I4, hithres, lowthres);
% perform the circular Hough transform
h = houghcircle(edgeimage, lradsc, uradsc);
maxtotal = 0;
% find the maximum in the Hough space, and hence
% the parameters of the circle
for i=1:rd
layer = h(:,:,i);
[maxlayer] = max(max(layer));
if maxlayer > maxtotal
maxtotal = maxlayer;
r = int32((lradsc+i) / scaling);
[row,col] = ( find(layer == maxlayer) );
row = int32(row(1) / scaling); % returns only first max value
col = int32(col(1) / scaling);
end
end