help bwferet
BWFERET Measure Feret diameters and angles of image regions.
OUT = BWFERET(I) measures the maximum Feret Properties of each
component (object) in the image. I can be a binary image, connected
component or labeled matrix.
OUT = BWFERET(BW, PROPERTIES) measures a set of Feret properties of each
connected component (object) in the binary image BW, which is a logical
array.
OUT = BWFERET(CC, PROPERTIES) measures a set of Feret properties of each
connected component (object) in CC, which is a struct returned by
BWCONNCOMP.
OUT = BWFERET(L, PROPERTIES) measures a set of Feret properties of
each labeled component (object) in the label matrix L. Positive integer
elements of L correspond to different regions. For example, the set of
elements of L equal to 1 corresponds to region 1; the set of elements of
L equal to 2 corresponds to region 2; and so on.
[OUT, L] = BWFERET(...) measures a set of Feret properties of each
component (object) in the binary image, connected component or labeled
matrix. This also returns the corresponding label matrix L such that
the first value in the table OUT corresponds to the labeled region
1, the second value with the labeled region 2 and so on.
PROPERTIES can be an array of strings, a single character vector, a cell
array of character vectors, or 'all'. If PROPERTIES is set to 'all' it
returns all the Feret properties mentioned below. If no argument is
provided, all maximum Feret properties are given as outputs. The set of
valid measurement strings or character vectors includes
'MaxFeretProperties', 'MinFeretProperties' and 'all'.
'MaxFeretProperties' - Outputs all the properties related to maximum
Feret Diameter.
These properties are:
MaxDiameter - Maximum Feret diameter length.
MaxAngle - Angle of maximum Feret diameter with respect to X
axis in degrees. The value lies between 180 to -180
degrees.
MaxCoordinates - Endpoint coordinates of maximum Feret diameter.
'MinFeretProperties' - Outputs all the properties related to minimum
Feret Diameter.
These properties are:
MinDiameter - Minimum Feret diameter length.
MinAngle - Angle of minimum Feret diameter with respect to X
axis in degrees. The value lies between 180 to -180
degrees.
MinCoordinates - Endpoint coordinates of minimum Feret diameter.
Class Support
-------------
If the first input is BW, BW must be a logical array and it should be 2D.
If the first input is CC, CC must be a structure returned by BWCONNCOMP.
If the first input is L, L must be real, nonsparse and 2D. L can have
any numeric class. The output OUT is returned as a table.
Example 1
---------
% Calculate the minimum Feret diameter for objects in image
I = imread('toyobjects.png');
bw = imbinarize(I, 'adaptive');
% Retain the two biggest objects in the image
bw = bwareafilt(bw, 2);
bw = imfill(bw, 'holes');
% Calculate the Feret properties of the objects in the image along with
% the label matrix
[out, L] = bwferet(bw, 'MinFeretProperties');
Example 2
---------
% Plot the maximum Feret diameter for objects in the image
% Read an image
I = imread('toyobjects.png');
% Binarize the image
B = imbinarize(I, 'adaptive');
% Fill in the holes in the binary image
B = imfill(B, 'holes');
% Show the image
h = imshow(B)
ax = h.Parent;
% Convert to connected component struct using bwconncomp
C = bwconncomp(B);
% Calculate Feret Properties
F = bwferet(C, 'MaxFeretProperties');
hold on
% Display maximum Feret Diameters with their values for each object
imdistline(ax, F.MaxCoordinates{1}(:,1), F.MaxCoordinates{1}(:,2));
imdistline(ax, F.MaxCoordinates{2}(:,1), F.MaxCoordinates{2}(:,2));
imdistline(ax, F.MaxCoordinates{3}(:,1), F.MaxCoordinates{3}(:,2));
imdistline(ax, F.MaxCoordinates{4}(:,1), F.MaxCoordinates{4}(:,2));
See also BWCONNCOMP, BWLABEL, BWLABELN, LABELMATRIX, REGIONPROPS.
Documentation for bwferet
doc bwferet