MaxFeretDiameter value using regionprop - Matlab

Viewed 370

How can I get the MaxFeretDiameter value in the MaxFeretProperties regionprop?

Code:

url='http://www.myiconfinder.com/uploads/iconsets/256-256-a0e17c0238c8bd1f805435f7cf132fc1-message.png';

Image = imread(url);
Image = rgb2gray(Image);
Image = imcomplement(Image);

BW = imbinarize(Image);
imshow(BW);
[B,L] = bwboundaries(BW,'noholes');

stat = regionprops(Image,'Centroid', 'MaxFeretProperties' );
disp(stat.MaxFeretProperties);

Error :

Reference to non-existent field 'MaxFeretProperties'.

Error in Untitled1 (line 17)
disp(stat.MaxFeretProperties);
1 Answers

Feret properties were added to regionprops in MATLAB R2019a. If your version of MATLAB is older than that, it will not know the 'MaxFeretProperties' option.

Adding the 'MaxFeretProperties' option to regionprops will add three features to the output struct. You can see this by examining it:

>> BW = ~imbinarize(Image);                                % NOTE! invert result so the object pixels are 1 and background pixels are 0.
>> stat = regionprops(BW,'Centroid','MaxFeretProperties'); % NOTE! input binary image here!
>> stat

stat = 

  struct with fields:

               Centroid: [139.3095 124.9653]
       MaxFeretDiameter: 274.7217
          MaxFeretAngle: 132.0492
    MaxFeretCoordinates: [2×2 double]

Thus, stat(ii).MaxFeretDiameter will give the maximum Feret diameter for object number ii.

For those interested in learning more about Feret diameters, I wrote a blog post many years ago detailing an efficient algorithm to compute it.

Related