Six numbers for a shape, and the convention behind each one.
Area, perimeter, circularity, Feret diameters, aspect ratio and solidity look like obvious measurements. Almost all of them have more than one definition in use, and two honest definitions give different numbers for the same seed. Here are the calculations, what each number ignores and where each one goes wrong.
Go deeper · mathematics and references
Area: counting pixels or integrating the outline
In a segmented image, the seed is a set of pixels. The simplest area comes from counting them, \(A_{\text{px}} = N\), in px², which becomes mm² when multiplied by the square of the pixel side. The other area comes from the outline. If the edge is a polygon with vertices \((x_i, y_i)\), \(i = 0, \dots, n-1\), closed with \((x_n, y_n) = (x_0, y_0)\), the area follows from the shoelace formula:
Result · shoelace formula
For a simple closed curve \(\gamma\) enclosing the region \(\Omega\), traversed counterclockwise, Green's theorem with \(P = -y/2\) and \(Q = x/2\) gives \(\partial_x Q - \partial_y P = 1\), and therefore
On a straight side from \((x_i, y_i)\) to \((x_{i+1}, y_{i+1})\), with \(x = x_i + t\,\Delta x\) and \(y = y_i + t\,\Delta y\), the integrand \(x\,\Delta y - y\,\Delta x\) is constant and equal to \(x_i y_{i+1} - x_{i+1} y_i\). Summing over the sides gives (1). The sign of the sum tells the direction of traversal, and the absolute value removes that dependence (in image coordinates, with \(y\) pointing down, the direction is reversed).
The two areas do not give the same number, and the difference has an exact formula when the polygon passes through the centers of the edge pixels, such as the 8-neighbor trace that follows the edge. The vertices become points of an integer lattice, and Pick's theorem [6] applies.
Result · half a pixel per edge pixel
Let \(N\) be the number of seed pixels and \(B\) the number of pixels on the edge trace, each counted once. The area of the polygon joining the centers of the edge pixels is
Sketch: by Pick's theorem, a simple polygon with vertices at integer points has area \(I + B/2 - 1\), where \(I\) is the number of integer points in the interior and \(B\) the number on the boundary. The seed pixels are exactly these points, interior and boundary together, so \(N = I + B\). This holds as long as the trace does not pass twice through the same pixel, that is, when there is no isthmus one pixel wide. We checked (3) on digital ellipses: the difference between the two sides was zero, up to machine rounding.
The polygon through the centers loses half a pixel per edge pixel. On a digital ellipse of 221 × 64 px this removes 1.9% of the count; on one of 55 × 16 px, 7.9%. Neither area is wrong. The count has no bias when a pixel is included by its center, and the polygon measures the region half a pixel inward. What matters is knowing which of the two is in the spreadsheet, and not mixing them in the same calculation (this is what goes wrong in circularity, further below).
Perimeter: the length depends on the ruler
The perimeter is the most treacherous of the six measurements. A real edge is irregular at many scales, and the measured length grows as the ruler shrinks, which is Mandelbrot's coastline of Britain problem [5]. In an image the ruler is the pixel, and even a perfectly smooth edge becomes a staircase.
Freeman [1] encoded the edge as a chain of steps between neighboring pixels, each step in one of 8 directions, 45° apart. The natural length of the chain counts 1 for each horizontal or vertical step and \(\sqrt2\) for each diagonal:
This length overestimates, and we can work out by how much. Take a straight stretch of edge, of length 1, at angle \(\theta \in [0, \pi/4]\) to the horizontal. It advances \(\cos\theta\) horizontally and \(\sin\theta\) vertically. The shortest path on the 8-neighbor grid takes \(\sin\theta\) diagonal steps and \(\cos\theta - \sin\theta\) straight ones, and measures
It equals 1 at 0° and at 45°, and reaches \(\sqrt{4 - 2\sqrt2} \approx 1{,}0824\) at 22.5°: up to 8.2% more only because of the direction of the stretch.
Result · Freeman's mean factor
If the seed edge has no preferred direction, \(\theta\) is uniform, and by symmetry the interval \([0, \pi/4]\) is enough:
The 8-neighbor chain overestimates the perimeter of a smooth edge by 5.48% on average. For the 4-neighbor chain, with straight steps only, the factor is \(\cos\theta + \sin\theta\) and the mean gives \(4/\pi \approx 1{,}273\). Dividing by the mean factor is Kulpa's correction [2], that is, multiplying by \(\pi/(8(\sqrt2 - 1)) \approx 0{,}948\).
The calculation was checked on real data. On 1,904 rice grains from a published dataset [10][11], the ratio between the perimeters from the two rulers, SeedCounter's and the dataset's, came to 1.054052, within 0.07% of the theoretical value: one of the two follows the 8-neighbor chain and the other corrects for the bias. The correction gets the mean right but not each stretch: with the factor 0.948, a stretch at 22.5° still comes out 2.6% too long and a horizontal stretch comes out 5.2% too short. Estimators that look at several steps at once do better [3][4].
Circularity and the isoperimetric inequality
Result · isoperimetric inequality
Every simple closed plane curve of length \(P\) encloses an area \(A\) with
and equality holds only for the circle [7]. Hence \(0 \lt C \le 1\) for any curve, and \(C = 1\) identifies the circle. For the circle of radius \(r\), \(4\pi\cdot\pi r^2 = (2\pi r)^2\).
Some values to keep at hand: the square gives \(\pi/4 \approx 0{,}785\); the ellipse whose length is twice its width, 0.84; the regular polygon with \(n\) sides, \(C_n = \pi / (n\tan(\pi/n))\), which gives 0.9986 with 48 sides. The orchid seed in the kit sits near 0.4.
In an image, however, circularity easily exceeds 1. Inequality (8) holds for a curve and the area of that same curve. When the area comes from one convention and the perimeter from another, it guarantees nothing. The table measures the same digital disk in four ways.
| radius | count and pixel edge (4-neighbor) | polygon through the centers | count and 8-neighbor chain | count and corrected chain |
|---|---|---|---|---|
| 3 px | 0,63 | 0,86 | 1,23 | 1,37 |
| 5 px | 0,62 | 0,89 | 1,08 | 1,20 |
| 10 px | 0,62 | 0,90 | 0,98 | 1,10 |
| 20 px | 0,62 | 0,90 | 0,94 | 1,04 |
| 50 px | 0,62 | 0,90 | 0,91 | 1,02 |
Circularity of digital disks, mean of 40 disks with the center drawn at random inside the pixel; in orange, values above 1. Our own simulation, rerun with the page's script.
The column for the polygon through the centers never exceeds 1, because there area and perimeter belong to the same curve. It stays below 1 and, for the larger disks, near \(1/1{,}0548^2 \approx 0{,}899\): the chain bias, squared. The 4-neighbor pixel edge tends to \(\pi^2/16 \approx 0{,}617\), because it measures the disk as a staircase of length \(8r\). And combining the pixel count, which extends to the outer edge, with a corrected perimeter, which passes through the centers, gives small circles with circularity near 1.4. Circularity can be compared only between measurements made with the same convention and at the same resolution.
Feret diameters and rotating calipers
The Feret diameter in a given direction is the opening of a caliper with its jaws perpendicular to that direction. With \(u_\theta = (\cos\theta, \sin\theta)\),
Since \(\langle p, u\rangle\) is linear in \(p\), the maximum and the minimum over the seed are the same as over its convex hull, and in a convex polygon they fall on vertices. The hull is therefore enough, and Andrew's monotone chain computes it in \(O(n\log n)\) [8].
Result · where the two diameters are
(a) \(F_{\max}\) is the largest distance between two hull vertices. (b) \(F_{\min}\) occurs with one caliper jaw lying against a hull edge: it is the smallest value, over the edges, of the largest distance from a vertex to the line of the edge.
Sketch of (b): between two directions in which some jaw lies against an edge, the two touched vertices stay fixed, say \(p\) and \(q\), and \(w(\theta) = \langle p - q, u_\theta\rangle = |p - q|\cos(\theta - \varphi)\), a concave function where it is positive. A concave function on an interval has its minimum at one of the endpoints, and the endpoints are exactly the directions in which a jaw lies against an edge.
The rotating calipers of Shamos and Toussaint use this: two supporting lines advance around the hull in one direction only and find both diameters in linear time once the hull is known [9]. The rotating caliper in Learn shows the same thing in motion. Feret is the most stable descriptor on the page: it depends only on the hull, and the hull ignores concavities and inward undulations.
Aspect ratio: two conventions
Length over width looks like a single calculation. There are two in use. The first is the caliper ratio, \(R_F = F_{\max}/F_{\min}\). The second comes from the inertia ellipse. The second-order central moments of the region,
form the covariance matrix of the region. With eigenvalues \(\lambda_1 \ge \lambda_2\), the uniform ellipse with the same moments has semi-axes \(a = 2\sqrt{\lambda_1}\) and \(b = 2\sqrt{\lambda_2}\), in the direction of the eigenvectors, and
For a polygon, the moments follow from Green's theorem, as the area does. The centroid, for example, is \(\bar x = \frac{1}{6A}\sum_i (x_i + x_{i+1})(x_i y_{i+1} - x_{i+1} y_i)\), and there are formulas of the same kind for \(\mu_{20}\), \(\mu_{11}\) and \(\mu_{02}\). This is how the track's mean seed shape aligned the seeds.
Result · the two ratios do not coincide
For an ellipse, \(R_F = R_E = a/b\). For a rectangle \(L \times W\), we have \(\lambda_1 = L^2/12\) and \(\lambda_2 = W^2/12\), so \(R_E = L/W\), while \(F_{\max}\) is the diagonal and \(R_F = \sqrt{L^2 + W^2}/W\). For the square, \(R_E = 1\) and \(R_F = \sqrt2 \approx 1{,}414\): the same figure is round by one convention and elongated by the other.
In the orchid seeds of the kit the median of \(R_F/R_E\) is 1.01, but in 32% of them the two ratios differ by more than 10%, and which one is larger depends on the shape. In curved seeds (solidity below 0.8), the Feret ratio comes out 9% lower at the median, because the minimum width spans the whole bend, not just the grain. In the nearly convex, angular label polygons (solidity of 0.95 or more), it comes out 7% higher, for the same reason as the square. Eccentricity carries the same information as \(R_E\), but squeezed near 1 for long seeds: ratio 3 gives 0.943, ratio 4 gives 0.968, ratio 5 gives 0.980. To compare elongated seeds, the ratio discriminates better than eccentricity.
Solidity and the convex hull
The hull \(\operatorname{conv}\Omega\) is the smallest convex set that contains the seed, the rubber band stretched around it. \(S = 1\) when the seed is convex, and it drops with any concavity: curvature, notch, break, two touching seeds. It is the natural descriptor for questioning an outline, because a cluster almost always has lower solidity than an isolated seed of the same species.
Like the area, the hull has two conventions in use: the convex polygon through the pixel centers, or the set of pixels that falls inside it. The second is larger, and the solidity changes along with it. It is one of the two conventions that explain the divergences in rice, just below.
What each number ignores
The ISO 9276-6 standard gives rules and nomenclature for describing particle shape, with almost all of the definitions in two dimensions, precisely because the measurement usually comes from image analysis [12]. The table summarizes what each of the six ignores and what gets in its way.
| descriptor | unit | scale \(s\) | what interferes |
|---|---|---|---|
| area | px² or mm² | \(\times s^2\) | edge convention, half a pixel per edge pixel (3) |
| perimeter | px or mm | \(\times s\) | resolution, chain neighborhood, outline simplification, direction of the stretches (5) |
| circularity | none | unchanged | everything that affects the perimeter, squared; mixing of conventions |
| Feret max. and min. | px or mm | \(\times s\) | very little: depends only on the hull |
| aspect ratio | none | unchanged | the convention, Feret or ellipse; seed curvature |
| solidity | none | unchanged | hull convention; outline detail (how many vertices it has) |
All six are invariant to translation and rotation in the continuous plane. On the grid, not exactly: rotating the seed in the photo does not change the pixel count, apart from the edge, but it does change the chain perimeter by up to 8.2% on a straight stretch, by equation (5). The three without units do not need the ruler, and that is why the Shape track could compare crops with different magnifications.
With real seeds
The 1,407 orchid seeds in the kit that do not touch the edge of the crop, measured on the label polygon:
| descriptor | viable (n = 775) | non-viable (n = 632) |
|---|---|---|
| label vertices | 25.5 ± 37.4median 12 | 20.6 ± 27.1median 9 |
| elongation, Feret max. ÷ min. | 4.27 ± 1.23median 4.12 | 3.89 ± 1.06median 3.76 |
| ratio from the ellipse axes | 4.28 ± 1.16median 4.16 | 3.85 ± 1.04median 3.75 |
| eccentricity | 0.965 ± 0.024median 0.971 | 0.957 ± 0.027median 0.964 |
| circularity | 0.370 ± 0.079median 0.364 | 0.420 ± 0.095median 0.414 |
| solidity | 0.856 ± 0.119median 0.883 | 0.897 ± 0.105median 0.924 |
Real data Mean ± standard deviation and median by class. Descriptors without units only: the crops do not share the same magnification, and what is measured in pixels mixes seed and zoom (see Size is misleading).
The viable class comes out slightly more elongated and slightly less circular, as the track's mean seed shape already showed. Solidity calls for caution, because it measures the label as much as the seed. Polygons with 4 to 8 vertices can hardly represent a concavity, and those of 13 to 20 already record curves and tips:
| label vertices | viable: solidity · circularity | non-viable: solidity · circularity |
|---|---|---|
| 4 a 8 | 0.98 · 0.42136 seeds | 0.98 · 0.44266 seeds |
| 9 a 12 | 0.90 · 0.36321 seeds | 0.90 · 0.39197 seeds |
| 13 a 20 | 0.80 · 0.33203 seeds | 0.77 · 0.3248 seeds |
| 60 or more (pixel trace) | 0.86 · 0.37111 seeds | 0.88 · 0.3973 seeds |
Real data Medians by range of the number of vertices of the label polygon. Labels with 60 vertices or more follow the edge pixels, as a staircase, and carry the chain bias with them.
Within the same vertex range, the two classes are similar in solidity. Since the viable seeds were outlined with more vertices (median 12 versus 9), part of the solidity difference between the classes in the first table comes from the outline and not from the seed. A descriptor measures the outline it receives.
Checked against a published dataset
On 1,904 rice grains, SeedCounter's calculations reproduced the shape descriptors of a published dataset [10][11]. Seven of eleven matched with 0.00% error: area, major and minor ellipse axes, eccentricity, equivalent diameter \(\sqrt{4A/\pi}\), extent (area over the area of the rectangle enclosing the seed) and compactness (equivalent diameter over major axis). The four divergences are explained by two conventions: the perimeter, which drags circularity along with it, and the convex hull area, which drags solidity. Where the definition is unique, the number is the same; where a convention exists, the difference is the convention.
Data
Dataset "Sementes de Orquídeas" v8, Roboflow Universe (universe.roboflow.com/sementes-de-orqudea/sementes-de-orquideas), license CC BY 4.0. Tables and simulations rerun with the site's script _src/figuras/teoria-forma-descritores.py.
Instrument: the polygon that loses vertices
The instrument runs the whole path of a measurement. A reference shape, the outline of a real seed from the kit smoothed to a curve, or an exact figure, is drawn on a pixel grid. The edge is followed with 8 neighbors, and the trace is reduced to \(n\) vertices taken at equal intervals along it. At each stage the calculations are redone. Roughness adds undulations 3 to 12 px long to the edge, like those a real segmentation leaves.
Instrument · from shape to polygon
| reference | pixel trace | polygon |
|---|
Thin line: the reference shape. Squares: the lit pixels. In the zoomed inset below, the left tip magnified nine times, with the pixel trace dotted. In the table, the pixel trace is the polygon through the centers of all the edge pixels (the 8-neighbor chain), and the percentages compare with the reference. In the chart, the polygon circularity divided by that of the reference for each number of vertices; the orange dot is the chosen one and the square on the right is the full trace.
Three things to look for. Without roughness and with many vertices, the trace perimeter stays near 5% above the reference, the Freeman factor of equation (6), and the trace circularity falls by 10 to 15%: the perimeter goes up and the area of the polygon through the centers goes down, by equation (3). With roughness, the polygon with few vertices cuts across the undulations, shortens the perimeter and inflates the circularity. And no \(n\) eliminates the error for every shape: the point where the curve crosses 1 changes with the shape, with the resolution and with the roughness. The area hardly moves with any of this; the perimeter, and with it the circularity, moves with everything.
In SeedCounter
In SeedCounter
For each outlined seed, the app computes area, perimeter and circularity on the outline; length and width along the principal axes of the outline, the directions of greatest and least spread, as in equation (11); and the maximum and minimum Feret diameters on the convex hull. The axes and Feret come out in separate columns, and the aspect ratio can be read from either convention. With the scale measured from the ruler, lengths come out in mm and areas in mm². The outline the app stores is a polygon of up to 48 vertices (the outline eraser works with up to 64).
Where it fails
Where it fails
The outline simplified to 48 sides overestimates circularity by +9.9% at the median, measured on 1,225 seeds against a reference perimeter. What drives the error is the solidity of the seed (correlation of −0.65, versus −0.29 for size and −0.28 for elongation): a seed with a concavity has edge detail that the 48 sides cut across in a straight line.
| seed solidity | measured ÷ reference circularity |
|---|---|
| 0.975 or more | 1,002 |
| 0.95 to 0.975 | 1,061 |
| 0.90 to 0.95 | 1,106 |
| below 0.90 | 1,308 |
Raising the number of vertices does not solve it: above about 192 vertices the error changes sign and turns into the pixel-staircase bias, as the instrument shows. The path the literature points to is to estimate the perimeter over the full trace, with corrected weights [2][3], and to keep the simplified polygon only for drawing.
Perimeter and circularity cannot be compared across images of different resolution, nor across outlines built in different ways. Length and area, with the scale read from each image, can.
A measurement of a few pixels is not a measurement. An orchid seed with a width of 0.2 mm spans 38 px in a 4,800 dpi scan and barely more than 2 px in a 300 dpi one. At 2 px wide, the aspect ratio is essentially random.
The two aspect ratios diverge for angular seeds and for curved ones. When you report one, say which.
References
- Freeman H. (1961). On the encoding of arbitrary geometric configurations. IRE Transactions on Electronic Computers EC-10(2), 260–268. doi:10.1109/TEC.1961.5219197
- Kulpa Z. (1977). Area and perimeter measurement of blobs in discrete binary pictures. Computer Graphics and Image Processing 6(5), 434–451. doi:10.1016/S0146-664X(77)80021-X
- Dorst L., Smeulders A. W. M. (1987). Length estimators for digitized contours. Computer Vision, Graphics, and Image Processing 40(3), 311–333. doi:10.1016/S0734-189X(87)80145-7
- Koplowitz J., Bruckstein A. M. (1989). Design of perimeter estimators for digitized planar shapes. IEEE Transactions on Pattern Analysis and Machine Intelligence 11(6), 611–622. doi:10.1109/34.24795
- Mandelbrot B. (1967). How long is the coast of Britain? Statistical self-similarity and fractional dimension. Science 156(3775), 636–638. doi:10.1126/science.156.3775.636
- Pick G. (1899). Geometrisches zur Zahlenlehre. Lotos, Zeitschrift für Naturwissenschaften 47, 311–319.
- Osserman R. (1978). The isoperimetric inequality. Bulletin of the American Mathematical Society 84(6), 1182–1238. doi:10.1090/S0002-9904-1978-14553-4
- Andrew A. M. (1979). Another efficient algorithm for convex hulls in two dimensions. Information Processing Letters 9(5), 216–219. doi:10.1016/0020-0190(79)90072-3
- Toussaint G. T. (1983). Solving geometric problems with the rotating calipers. In Proceedings of MELECON '83, Mediterranean Electrotechnical Conference, Athens, A10.02/1–4. IEEE.
- Cinar I., Koklu M. (2022). Identification of rice varieties using machine learning algorithms. Journal of Agricultural Sciences (Tarım Bilimleri Dergisi) 28(2), 307–325. doi:10.15832/ankutbd.862482
- Koklu M., Cinar I., Taspinar Y. S. (2021). Classification of rice varieties with deep learning methods. Computers and Electronics in Agriculture 187, 106285. doi:10.1016/j.compag.2021.106285
- ISO 9276-6:2008. Representation of results of particle size analysis, Part 6: Descriptive and quantitative representation of particle shape and morphology. International Organization for Standardization.
Every number with its own convention.
SeedCounter measures area, perimeter, circularity, axes and Feret diameter for each seed you check.