annotate inst/bwarea.m @ 897:d3ec45cd8660 stable release-2.2.2

maint: release 2.2.2.
author Carnë Draug <carandraug@octave.org>
date Mon, 06 Oct 2014 17:16:02 +0100
parents 71a92303203d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
676
71a92303203d image: change enconding to UTF-8
carandraug
parents: 615
diff changeset
1 ## Copyright (C) 2005 Søren Hauberg <soren@hauberg.org>
561
c45838839d86 maint: update license to GPLv3 and mention non GPL files
carandraug
parents: 274
diff changeset
2 ##
c45838839d86 maint: update license to GPLv3 and mention non GPL files
carandraug
parents: 274
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: 274
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: 274
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: 274
diff changeset
6 ## version.
c45838839d86 maint: update license to GPLv3 and mention non GPL files
carandraug
parents: 274
diff changeset
7 ##
c45838839d86 maint: update license to GPLv3 and mention non GPL files
carandraug
parents: 274
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: 274
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: 274
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: 274
diff changeset
11 ## details.
c45838839d86 maint: update license to GPLv3 and mention non GPL files
carandraug
parents: 274
diff changeset
12 ##
c45838839d86 maint: update license to GPLv3 and mention non GPL files
carandraug
parents: 274
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: 274
diff changeset
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
186
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
15
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
16 ## -*- texinfo -*-
615
8d3210ae9a4a bwarea: accept any class and objects are all non-zero instead of all higher than zero
carandraug
parents: 561
diff changeset
17 ## @deftypefn {Function File} {@var{total} =} bwarea (@var{bw})
8d3210ae9a4a bwarea: accept any class and objects are all non-zero instead of all higher than zero
carandraug
parents: 561
diff changeset
18 ## Estimate total area of objects on the image @var{bw}.
8d3210ae9a4a bwarea: accept any class and objects are all non-zero instead of all higher than zero
carandraug
parents: 561
diff changeset
19 ##
8d3210ae9a4a bwarea: accept any class and objects are all non-zero instead of all higher than zero
carandraug
parents: 561
diff changeset
20 ## The image @var{bw} can be of any class, even non-logical, in which case non
8d3210ae9a4a bwarea: accept any class and objects are all non-zero instead of all higher than zero
carandraug
parents: 561
diff changeset
21 ## zero valued pixels are considered to be an object.
8d3210ae9a4a bwarea: accept any class and objects are all non-zero instead of all higher than zero
carandraug
parents: 561
diff changeset
22 ##
8d3210ae9a4a bwarea: accept any class and objects are all non-zero instead of all higher than zero
carandraug
parents: 561
diff changeset
23 ## This algorithm is not the same as counting the number of pixels belonging to
8d3210ae9a4a bwarea: accept any class and objects are all non-zero instead of all higher than zero
carandraug
parents: 561
diff changeset
24 ## an object as it tries to estimate the area of the original object. The value
8d3210ae9a4a bwarea: accept any class and objects are all non-zero instead of all higher than zero
carandraug
parents: 561
diff changeset
25 ## of each pixel to the total area is weighted in relation to its neighbour
8d3210ae9a4a bwarea: accept any class and objects are all non-zero instead of all higher than zero
carandraug
parents: 561
diff changeset
26 ## pixels.
8d3210ae9a4a bwarea: accept any class and objects are all non-zero instead of all higher than zero
carandraug
parents: 561
diff changeset
27 ##
8d3210ae9a4a bwarea: accept any class and objects are all non-zero instead of all higher than zero
carandraug
parents: 561
diff changeset
28 ## @seealso{im2bw, bweuler, bwperim, regionprops}
186
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
29 ## @end deftypefn
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
30
615
8d3210ae9a4a bwarea: accept any class and objects are all non-zero instead of all higher than zero
carandraug
parents: 561
diff changeset
31 function total = bwarea (bw)
8d3210ae9a4a bwarea: accept any class and objects are all non-zero instead of all higher than zero
carandraug
parents: 561
diff changeset
32 if (nargin != 1)
8d3210ae9a4a bwarea: accept any class and objects are all non-zero instead of all higher than zero
carandraug
parents: 561
diff changeset
33 print_usage;
8d3210ae9a4a bwarea: accept any class and objects are all non-zero instead of all higher than zero
carandraug
parents: 561
diff changeset
34 elseif (!isimage (bw) || ndims (bw) != 2)
8d3210ae9a4a bwarea: accept any class and objects are all non-zero instead of all higher than zero
carandraug
parents: 561
diff changeset
35 error("bwarea: input image must be a 2D image");
8d3210ae9a4a bwarea: accept any class and objects are all non-zero instead of all higher than zero
carandraug
parents: 561
diff changeset
36 elseif (!islogical (bw))
8d3210ae9a4a bwarea: accept any class and objects are all non-zero instead of all higher than zero
carandraug
parents: 561
diff changeset
37 bw = (bw != 0)
186
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
38 endif
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
39
615
8d3210ae9a4a bwarea: accept any class and objects are all non-zero instead of all higher than zero
carandraug
parents: 561
diff changeset
40 four = ones (2);
8d3210ae9a4a bwarea: accept any class and objects are all non-zero instead of all higher than zero
carandraug
parents: 561
diff changeset
41 two = diag ([1 1]);
186
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
42
615
8d3210ae9a4a bwarea: accept any class and objects are all non-zero instead of all higher than zero
carandraug
parents: 561
diff changeset
43 fours = conv2 (bw, four);
8d3210ae9a4a bwarea: accept any class and objects are all non-zero instead of all higher than zero
carandraug
parents: 561
diff changeset
44 twos = conv2 (bw, two);
186
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
45
615
8d3210ae9a4a bwarea: accept any class and objects are all non-zero instead of all higher than zero
carandraug
parents: 561
diff changeset
46 nQ1 = sum (fours(:) == 1);
8d3210ae9a4a bwarea: accept any class and objects are all non-zero instead of all higher than zero
carandraug
parents: 561
diff changeset
47 nQ3 = sum (fours(:) == 3);
8d3210ae9a4a bwarea: accept any class and objects are all non-zero instead of all higher than zero
carandraug
parents: 561
diff changeset
48 nQ4 = sum (fours(:) == 4);
8d3210ae9a4a bwarea: accept any class and objects are all non-zero instead of all higher than zero
carandraug
parents: 561
diff changeset
49 nQD = sum (fours(:) == 2 & twos(:) != 1);
8d3210ae9a4a bwarea: accept any class and objects are all non-zero instead of all higher than zero
carandraug
parents: 561
diff changeset
50 nQ2 = sum (fours(:) == 2 & twos(:) == 1);
186
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
51
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
52 total = 0.25*nQ1 + 0.5*nQ2 + 0.875*nQ3 + nQ4 + 0.75*nQD;
615
8d3210ae9a4a bwarea: accept any class and objects are all non-zero instead of all higher than zero
carandraug
parents: 561
diff changeset
53
186
13c6a9bdec24 Changed the structure to match the package system
hauberg
parents:
diff changeset
54 endfunction