annotate inst/regionprops.m @ 396:39a521b5484e

More properties implemented
author hauberg
date Fri, 05 Mar 2010 02:48:26 +0000
parents 394c85635f2b
children c45838839d86
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
393
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
1 ## Copyright (C) 2010 Soren Hauberg
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
2 ##
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
3 ## This program is free software; you can redistribute it and/or modify
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
4 ## it under the terms of the GNU General Public License as published by
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
5 ## the Free Software Foundation; either version 3 of the License, or
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
6 ## (at your option) any later version.
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
7 ##
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
8 ## This program is distributed in the hope that it will be useful,
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
11 ## GNU General Public License for more details.
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
12 ##
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
13 ## You should have received a copy of the GNU General Public License
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
14 ## along with this program; If not, see <http://www.gnu.org/licenses/>.
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
15
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
16 ## -*- texinfo -*-
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
17 ## @deftypefn {Function File} {@var{props} = } regionprops (@var{BW})
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
18 ## @deftypefnx {Function File} {@var{props} = } regionprops (@var{BW}, @var{properties}, @dots{})
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
19 ## Compute object properties in a binary image.
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
20 ##
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
21 ## @code{regionprops} computes various properties of the individual objects (as
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
22 ## identified by @code{bwlabel}) in the binary image @var{BW}. The result is a
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
23 ## structure array containing an entry per property per object.
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
24 ##
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
25 ## The following properties can be computed.
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
26 ##
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
27 ## @table @t
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
28 ## @item "Area"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
29 ## The number of pixels in the object.
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
30 ## @item "EulerNumber"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
31 ## @itemx "euler_number"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
32 ## The Euler number of the object (see @code{bweuler} for details).
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
33 ## @item "BoundingBox"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
34 ## @itemx "bounding_box"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
35 ## The bounding box of the object. This is represented as a 4-vector where the
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
36 ## first two entries are the @math{x} and @math{y} coordinates of the upper left
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
37 ## corner of the bounding box, and the two last entries are the width and the
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
38 ## height of the box.
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
39 ## @item "Extent"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
40 ## The area of the object divided by the area of the bounding box.
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
41 ## @item "Perimeter"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
42 ## The length of the boundary of the object.
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
43 ## @item "Centroid"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
44 ## The center coordinate of the object.
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
45 ## @item "PixelIdxList"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
46 ## @itemx "pixel_idx_list"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
47 ## The indices of the pixels in the object.
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
48 ## @item "FilledArea"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
49 ## @itemx "filled_area"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
50 ## The area of the object including possible holes.
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
51 ## @item "PixelList"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
52 ## @itemx "pixel_list"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
53 ## The actual pixel values inside the object. This is only useful for grey scale
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
54 ## images.
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
55 ## @item "FilledImage"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
56 ## @itemx "filled_image"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
57 ## A binary image with the same size as the object's bounding box that contains
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
58 ## the object with all holes removed.
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
59 ## @item "Image"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
60 ## An image with the same size as the bounding box that contains the original pixels.
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
61 ## @item "MaxIntensity"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
62 ## @itemx "max_intensity"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
63 ## The maximum intensity inside the object.
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
64 ## @item "MinIntensity"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
65 ## @itemx "min_intensity"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
66 ## The minimum intensity inside the object.
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
67 ## @item "WeightedCentroid"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
68 ## @itemx "weighted_centroid"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
69 ## The centroid of the object where pixel values are used as weights.
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
70 ## @item "MeanIntensity"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
71 ## @itemx "mean_intensity"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
72 ## The mean intensity inside the object.
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
73 ## @item "PixelValues"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
74 ## @itemx "pixel_values"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
75 ## The pixel values inside the object represented as a vector.
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
76 ## @end table
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
77 ##
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
78 ## The requested properties can either be specified as several input arguments
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
79 ## or as a cell array of strings. As a short-hand it is also possible to give
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
80 ## the following strings as arguments.
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
81 ##
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
82 ## @table @t
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
83 ## @item "basic"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
84 ## The following properties are computed: @t{"Area"}, @t{"Centroid"} and @t{"BoundingBox"}.
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
85 ## @item "all"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
86 ## All properties are computed.
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
87 ## @end table
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
88 ##
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
89 ## If no properties are given, @t{basic} is assumed.
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
90 ## @seealso{bwlabel, bwperim, bweuler}
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
91 ## @end deftypefn
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
92
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
93 function retval = regionprops (bw, varargin)
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
94 ## Check input
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
95 if (nargin < 1)
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
96 error ("regionprops: not enough input arguments");
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
97 endif
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
98
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
99 if (!ismatrix (bw) || ndims (bw) != 2)
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
100 error ("regionprops: first input argument must be a NxM matrix");
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
101 endif
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
102
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
103 if (numel (varargin) == 0)
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
104 properties = "basic";
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
105 elseif (numel (varargin) == 1 && iscellstr (varargin {1}))
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
106 properties = varargin {1};
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
107 elseif (iscellstr (varargin))
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
108 properties = varargin;
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
109 else
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
110 error ("regionprops: properties must be a cell array of strings");
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
111 endif
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
112
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
113 if (ischar (properties) && strcmpi (properties, "basic"))
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
114 properties = {"Area", "Centroid", "BoundingBox"};
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
115 elseif (ischar (properties) && strcmpi (properties, "all"))
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
116 properties = {"area", "eulernumber", "boundingbox", "extent", "perimeter", ...
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
117 "centroid", "pixelidxlist", "filledarea", "pixellist", ...
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
118 "filledimage", "image", "maxintensity", "minintensity", ...
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
119 "weightedcentroid", "meanintensity", "pixelvalues"};
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
120 elseif (!iscellstr (properties))
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
121 error ("%s %s", "regionprops: properties must be specified as a list of",
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
122 "strings or a cell array of strings");
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
123 endif
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
124
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
125 ## Get a labelled image
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
126 if (!islogical (bw) && all (bw >= 0) && all (bw == round (bw)))
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
127 L = bw; # the image was already labelled
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
128 num_labels = max (L (:));
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
129 else
396
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
130 [L, num_labels] = bwlabel (bw);
393
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
131 endif
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
132
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
133 ## Compute the properties
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
134 retval = struct ();
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
135 for k = 1:numel (properties)
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
136 switch (lower (properties {k}))
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
137 case "area"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
138 for k = 1:num_labels
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
139 retval (k).Area = local_area (L == k);
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
140 endfor
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
141
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
142 case {"eulernumber", "euler_number"}
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
143 for k = 1:num_labels
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
144 retval (k).EulerNumber = bweuler (L == k);
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
145 endfor
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
146
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
147 case {"boundingbox", "bounding_box"}
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
148 for k = 1:num_labels
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
149 retval (k).BoundingBox = local_boundingbox (L == k);
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
150 endfor
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
151
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
152 case "extent"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
153 for k = 1:num_labels
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
154 bb = local_boundingbox (L == k);
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
155 area = local_area (L == k);
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
156 retval (k).Extent = area / (bb (3) * bb (4));
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
157 endfor
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
158
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
159 case "perimeter"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
160 for k = 1:num_labels
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
161 retval (k).Perimeter = sum (bwperim (L == k) (:));
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
162 endfor
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
163
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
164 case "centroid"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
165 for k = 1:num_labels
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
166 [Y, X] = find (L == k);
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
167 retval (k).Centroid = [mean(X), mean(Y)];
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
168 endfor
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
169
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
170 case {"pixelidxlist", "pixel_idx_list"}
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
171 for k = 1:num_labels
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
172 retval (k).PixelIdxList = find (L == k);
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
173 endfor
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
174
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
175 case {"filledarea", "filled_area"}
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
176 for k = 1:num_labels
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
177 retval (k).FilledArea = sum (bwfill (L == k, "holes") (:));
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
178 endfor
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
179
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
180 case {"pixellist", "pixel_list"}
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
181 for k = 1:num_labels
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
182 [Y, X] = find (L == k);
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
183 retval (k).PixelList = [X, Y];
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
184 endfor
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
185
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
186 case {"filledimage", "filled_image"}
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
187 for k = 1:num_labels
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
188 retval (k).FilledImage = bwfill (L == k, "holes");
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
189 endfor
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
190
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
191 case "image"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
192 for k = 1:num_labels
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
193 tmp = (L == k);
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
194 [R, C] = find (tmp);
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
195 retval (k).Image = tmp (min (R):max (R), min (C):max (C));
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
196 endfor
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
197
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
198 case {"maxintensity", "max_intensity"}
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
199 for k = 1:num_labels
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
200 retval (k).MaxIntensity = max (bw (L == k) (:));
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
201 endfor
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
202
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
203 case {"minintensity", "min_intensity"}
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
204 for k = 1:num_labels
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
205 retval (k).MaxIntensity = min (bw (L == k) (:));
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
206 endfor
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
207
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
208 case {"weightedcentroid", "weighted_centroid"}
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
209 for k = 1:num_labels
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
210 [Y, X] = find (L == k);
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
211 vals = bw (L == k) (:);
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
212 vals /= sum (vals);
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
213 retval (k).WeightedCentroid = [dot(X, vals), dot(Y, vals)];
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
214 endfor
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
215
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
216 case {"meanintensity", "mean_intensity"}
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
217 for k = 1:num_labels
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
218 retval (k).MaxIntensity = mean (bw (L == k) (:));
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
219 endfor
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
220
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
221 case {"pixelvalues", "pixel_values"}
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
222 for k = 1:num_labels
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
223 retval (k).PixelValues = bw (L == k)(:);
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
224 endfor
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
225
396
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
226 case "orientation"
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
227 for k = 1:num_labels
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
228 [Y, X] = find (L == k);
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
229 if (numel (Y) > 1)
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
230 C = cov ([X(:), Y(:)]);
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
231 [V, lambda] = eig (C);
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
232 [max_val, max_idx] = max (diag (lambda));
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
233 v = V (:, max_idx);
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
234 retval (k).Orientation = 180 - 180 * atan2 (v (2), v (1)) / pi;
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
235 else
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
236 retval (k).Orientation = 0; # XXX: What does the other brand do?
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
237 endif
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
238 endfor
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
239
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
240 %{
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
241 case "majoraxislength"
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
242 for k = 1:num_labels
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
243 [Y, X] = find (L == k);
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
244 if (numel (Y) > 1)
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
245 C = cov ([X(:), Y(:)]);
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
246 lambda = eig (C);
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
247 retval (k).MajorAxisLength = (max (lambda));
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
248 else
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
249 retval (k).MajorAxisLength = 1;
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
250 endif
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
251 endfor
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
252
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
253 case "minoraxislength"
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
254 for k = 1:num_labels
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
255 [Y, X] = find (L == k);
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
256 if (numel (Y) > 1)
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
257 C = cov ([X(:), Y(:)]);
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
258 lambda = eig (C);
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
259 retval (k).MinorAxisLength = (min (lambda));
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
260 else
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
261 retval (k).MinorAxisLength = 1;
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
262 endif
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
263 endfor
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
264 %}
39a521b5484e More properties implemented
hauberg
parents: 393
diff changeset
265
393
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
266 #case "extrema"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
267 #case "convexarea"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
268 #case "convexhull"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
269 #case "solidity"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
270 #case "conveximage"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
271 #case "subarrayidx"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
272 #case "eccentricity"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
273 #case "equivdiameter"
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
274
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
275 otherwise
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
276 error ("regionprops: unsupported property '%s'", properties {k});
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
277 endswitch
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
278 endfor
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
279 endfunction
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
280
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
281 function retval = local_area (bw)
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
282 retval = sum (bw (:));
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
283 endfunction
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
284
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
285 function retval = local_boundingbox (bw)
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
286 [Y, X] = find (bw);
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
287 retval = [min(X)-0.5, min(Y)-0.5, max(X)-min(X)+1, max(Y)-min(Y)+1];
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
288 endfunction
394c85635f2b New function: regionprops
hauberg
parents:
diff changeset
289