Mercurial > hg > octave-image
annotate inst/houghtf.m @ 821:72cd72a3bff6
bestblk: complete rewrite to suppport multi-dimensional matrices.
* bestblk.m: implement support for any number of dimensions. Vectorize
code (loop only over dimensions now). Add tests.
* NEWS: new section for functions now supporting N-dimensional matrices.
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Fri, 01 Nov 2013 05:05:28 +0000 |
parents | c6be7812523a |
children |
rev | line source |
---|---|
709 | 1 ## Copyright (C) 2008 Søren Hauberg <soren@hauberg.org> |
561
c45838839d86
maint: update license to GPLv3 and mention non GPL files
carandraug
parents:
463
diff
changeset
|
2 ## |
c45838839d86
maint: update license to GPLv3 and mention non GPL files
carandraug
parents:
463
diff
changeset
|
3 ## This program is free software; you can redistribute it and/or modify it under |
c45838839d86
maint: update license to GPLv3 and mention non GPL files
carandraug
parents:
463
diff
changeset
|
4 ## the terms of the GNU General Public License as published by the Free Software |
c45838839d86
maint: update license to GPLv3 and mention non GPL files
carandraug
parents:
463
diff
changeset
|
5 ## Foundation; either version 3 of the License, or (at your option) any later |
c45838839d86
maint: update license to GPLv3 and mention non GPL files
carandraug
parents:
463
diff
changeset
|
6 ## version. |
c45838839d86
maint: update license to GPLv3 and mention non GPL files
carandraug
parents:
463
diff
changeset
|
7 ## |
c45838839d86
maint: update license to GPLv3 and mention non GPL files
carandraug
parents:
463
diff
changeset
|
8 ## This program is distributed in the hope that it will be useful, but WITHOUT |
c45838839d86
maint: update license to GPLv3 and mention non GPL files
carandraug
parents:
463
diff
changeset
|
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
c45838839d86
maint: update license to GPLv3 and mention non GPL files
carandraug
parents:
463
diff
changeset
|
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
c45838839d86
maint: update license to GPLv3 and mention non GPL files
carandraug
parents:
463
diff
changeset
|
11 ## details. |
c45838839d86
maint: update license to GPLv3 and mention non GPL files
carandraug
parents:
463
diff
changeset
|
12 ## |
c45838839d86
maint: update license to GPLv3 and mention non GPL files
carandraug
parents:
463
diff
changeset
|
13 ## You should have received a copy of the GNU General Public License along with |
c45838839d86
maint: update license to GPLv3 and mention non GPL files
carandraug
parents:
463
diff
changeset
|
14 ## this program; if not, see <http://www.gnu.org/licenses/>. |
287 | 15 |
16 ## -*- texinfo -*- | |
17 ## @deftypefn {Function File} @var{H} = houghtf (@var{bw}) | |
18 ## @deftypefnx{Function File} @var{H} = houghtf (@var{bw}, @var{method}) | |
19 ## @deftypefnx{Function File} @var{H} = houghtf (@var{bw}, @var{method}, @var{arg}) | |
20 ## Perform the Hough transform for lines or circles. | |
21 ## | |
22 ## The @var{method} argument chooses between the Hough transform for lines and | |
23 ## circles. It can be either "line" (default) or "circle". | |
24 ## | |
25 ## @strong{Line Detection} | |
26 ## | |
27 ## If @var{method} is "line", the function will compute the Hough transform for | |
28 ## lines. A line is parametrised in @var{r} and @var{theta} as | |
29 ## @example | |
30 ## @var{r} = x*cos(@var{theta}) + y*sin(@var{theta}), | |
31 ## @end example | |
32 ## where @var{r} is distance between the line and the origin, while @var{theta} | |
33 ## is the angle of the vector from the origin to this closest point. The result | |
34 ## @var{H} is an @var{N} by @var{M} matrix containing the Hough transform. Here, | |
35 ## @var{N} is the number different values of @var{r} that has been attempted. | |
36 ## This is computed as @code{2*diag_length - 1}, where @code{diag_length} is | |
37 ## the length of the diagonal of the input image. @var{M} is the number of | |
38 ## different values of @var{theta}. These can be set through the third input | |
39 ## argument @var{arg}. This must be a vector of real numbers, and is by default | |
40 ## @code{pi*(-90:90)/180}. | |
41 ## | |
42 ## @strong{Circle Detection} | |
43 ## | |
44 ## If @var{method} is "circle" the function will compute the Hough transform for | |
45 ## circles. The circles are parametrised in @var{r} which denotes the radius of | |
46 ## the circle. The third input argument @var{arg} must be a real vector containing | |
47 ## the possible values of @var{r}. | |
48 ## If the input image is @var{N} by @var{M}, then the result @var{H} will be an | |
49 ## @var{N} by @var{M} by @var{K} array, where @var{K} denotes the number of | |
50 ## different values of @var{r}. | |
51 ## | |
52 ## As an example, the following shows how to compute the Hough transform for circles | |
53 ## with radius 3 or 7 in the image @var{im} | |
54 ## @example | |
55 ## bw = edge(im); | |
56 ## H = houghtf(bw, "circle", [3, 7]); | |
57 ## @end example | |
58 ## Here @var{H} will be an NxMx2 array, where @var{H}(:,:,1) will contain the | |
59 ## Hough transform for circles with radius 3, and @var{H}(:,:,2) for radius 7. | |
60 ## To find good circles you now need to find local maximas in @var{H}. If you | |
61 ## find a local maxima in @var{H}(row, col, 1) it means that a good circle exists | |
294 | 62 ## with center (row,col) and radius 3. One way to locate maximas is to use the |
63 ## @code{immaximas} function. | |
287 | 64 ## |
294 | 65 ## @seealso{hough_line, hough_circle, immaximas} |
287 | 66 ## @end deftypefn |
67 | |
68 function [accum, R] = houghtf(bw, varargin) | |
69 ## Default arguments | |
70 method = "line"; | |
71 args = {}; | |
72 | |
73 ## Check input arguments | |
74 if (nargin == 0) | |
75 error("houghtf: not enough input arguments"); | |
76 endif | |
77 | |
78 if (!ismatrix(bw) || ndims(bw) != 2) | |
79 error("houghtf: first arguments must be a 2-dimensional matrix"); | |
80 endif | |
81 | |
82 if (nargin > 1) | |
83 if (ischar(varargin{1})) | |
84 method = varargin{1}; | |
323 | 85 args = varargin(2:end); |
287 | 86 else |
323 | 87 args = varargin; |
287 | 88 endif |
89 endif | |
90 | |
91 ## Choose method | |
92 switch (lower(method)) | |
93 case "line" | |
323 | 94 [accum, R] = hough_line(bw, args{:}); |
287 | 95 case "circle" |
323 | 96 accum = hough_circle(bw, args{:}); |
287 | 97 otherwise |
98 error("houghtf: unsupported method '%s'", method); | |
99 endswitch | |
100 | |
101 endfunction |