2

Can someone please explain me why the 'Circularity' in Matlab is calculated by (4*Area*pi)/(Perimeter^2) while in Podczeck Shape it is Area/(Pi/4*sp^2) https://qiftp.tudelft.nl/dipref/FeatureShape.html)? Or is it just simply defined differently?

I tried to write a Podczeck Shape circularity code in Matlab and I assume that ‘MaxFeretDiameter’ is perpendicular to ‘MinFeretDiameter’, am I correct?

Code:

clc;
clear all;
close all;

Pi=pi;
Image = rgb2gray(imread('pillsetc.png'));

BW = imbinarize(Image);
BW = imfill(BW,'holes');
BW = bwareaopen(BW, 100);
imshow(BW);

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

i=2; 
stat = regionprops(BW, 'Area', 'Circularity', 'MaxFeretProperties', 'MinFeretProperties');
OArea = stat(i).Area;
OMaxFeretProperties = stat(i).MaxFeretDiameter; 
OMinFeretProperties = stat(i).MinFeretDiameter;   
OCircularityPodzeck = OArea/(Pi/4 * (OMaxFeretProperties^2))
OCircularityMatlab = stat(i).Circularity
Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
wrek
  • 309
  • 2
  • 13

1 Answers1

1

The 'Circularity' measure in regionprops is defined as

Circularity = (4 Area π)/(Perimeter²)

For a circle, where Area = π r² and Perimeter = 2 π r, this comes out to:

Circularity = (4 π r² π)/((2 π r)²) = (4 π² r²)/(4 π² r²) = 1

For any other shape, the perimeter will be relatively longer (this is a characteristic of the circle!), and so the 'Circularity' measure will be smaller.

Podczeck's Circularity is a different measure. It is defined as

Podczeck Circularity = Area/(π/4 Height²)

In the documentation you link it refers to Height as sp, and defines it as "Feret diameter perpendicular to s", and defines s as "the shortest Feret diameter". Thus, sp is the largest of the two sides of the minimal bounding box.

For a circle, the minimal bounding box has Height equal to the diameter. We substitute again:

Podczeck Circularity = (π r²)/(π/4 (2 r)²) = (π r²)/(π/4 4 r²) = 1

For any other shape, the height will be relatively larger, and so the Podczeck Circularity measure will be smaller.


Do note that the max and min Feret diameters are not necessarily perpendicular. A simple example is a square: the largest diameter is the diagonal of the square; the smallest diameter is the height or width; these two are at 45 degrees from each other. The Podczeck Circularity measure uses the size of the project perpendicular to the smallest projection, which for a square is equal to the smallest projection, and smaller than the largest projection. The smallest projection and its perpendicular projection form the minimal bounding rectangle (typically, though apparently this is not necessarily the case?). However, regionprops has a 'BoundingBox' that is axis-aligned, and therefore not suitable. I don't know how to get the required value out of regionprops.

The approach you would have to follow is to use the 'PixelList' output of regionprops, together with the 'MinFeretAngle'. 'PixelList' is a list of pixel coordinates that belong to the object. You would rotate these coordinates according to 'MinFeretAngle', such that the axis-aligned bounding rectangle now corresponds to the minimal bounding rectangle. You can then determine the size of the box by taking the minimum and maximum values of the rotated coordinates.

Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
  • Ok, thanks as lot for the detailed explanation. What about using the height and width (width = stat.BoundingBox(3); height = stat.BoundingBox(4);) of a rotated object (based on its regionprop orientation)? – wrek Apr 15 '20 at 19:41
  • @wrek: Yes, you could do that too. You just need `max(width,height)` for the Podczeck Circularity. – Cris Luengo Apr 15 '20 at 19:58