hilum

Theory · Image and measurement

How a photo becomes millimeters.

An image of seeds is a grid of colored pixels. To get a length in millimeters out of it, four things happen in order: the ruler gives the size of the pixel, a threshold separates the seed from the background, the outline closes each seed, and the measurement comes from the outline.

Understand · visual

Elongated, yellowish orchid seeds with a reddish embryo, on blue paper. Each labeled seed has its outline drawn: a solid cyan line on the viable ones and a dashed magenta line on the non-viable ones.
Real dataFigure 1. Orchid seeds after the tetrazolium test, on blue paper. The outlines are the dataset labels: solid cyan for viable, dashed magenta for non-viable. The crop has no ruler, so everything here is in pixels.

1 · Scale

A pixel only gets a size when the ruler says so

A pixel is a position on the grid. How many micrometers it covers depends on the camera distance, the lens and any crop made afterwards. A ruler photographed in the same plane as the seeds answers the question with one division: if 10 mm of the ruler span 400 pixels, each pixel corresponds to 10 mm ÷ 400 = 25 µm, that is, 40 px per millimeter.

This number, the scale \(s\), multiplies every length measured in pixels. The area is multiplied by \(s^2\). That is why a 1% error in the scale becomes 1% in length and 2% in area, in every seed in the image at once.

The DPI stored in the file is a declaration, not a measurement. On a flatbed scanner, the reported value was 3,600 dpi, and the ruler scanned in the image itself measured close to 4,750: measurements made with the declared value would come out 32% larger. The ruler calculation, with the uncertainty of each click, is in From pixel to millimeter.

Window of a plate with yellowish orchid seeds on blue paper; a square marks one of the seeds.

1 · 360 × 360 px window

The marked seed, enlarged: the pixels already show up as little squares along the edges.

2 · the seed, 114 × 114 px

The tip of the seed at 24 by 24 pixels: each pixel is a square of uniform color; the edge pixels are outlined in orange and a blue line runs between them.

3 · the tip, 24 × 24 px

Real dataFigure 2. The same seed at three magnifications. It covers 2,427 pixels, and 213 of them (8.8%) are edge pixels, with at least one background neighbor, marked in orange in panel 3. The blue line is where the threshold cuts the color, with sub-pixel precision: the true edge runs through the pixels, not between them.

Instrument · how much a pixel weighs

…pixel size
…length × width in pixels
…pixels in the seed
…of them on the edge
…±1 px in length
…±1 px in area

seed pixeledge pixeltrue outline

…

The seed is an ellipse with the chosen length and ratio, and a pixel counts as seed when its center falls inside. One pixel more or less at the edge changes the length by \(1/L\) and the area by about \(1/L + 1/W\), with \(L\) and \(W\) in pixels: the derivation is in From pixel to millimeter.

2 · Seed and background

A threshold decides what is seed

Each pixel holds a color. To separate the seed from the background, the computation chooses a color axis along which the two are well apart and a threshold on that axis. Here the paper is blue and the seeds are yellowish or red, so the blue-yellow axis of the color, b* of the CIELAB color space, separates them well. Otsu's method chooses the threshold that leaves the two populations of pixels as far apart as possible [1]. Everything above it becomes seed.

360 by 360 pixel window with four sharp seeds and several blurred ones on blue paper.

1 · the image

The same window after thresholding: the pixels above the threshold in orange on a dark background, including blobs from the blurred seeds.

2 · above the threshold

The darkened window with the outline of each blob: the four labeled seeds numbered 1 to 4 with the largest diameter in orange, and the blurred blobs with a dashed outline.

3 · outline and length

Real dataFigure 3. From pixel to measurement in a window of another plate. The Otsu threshold on the blue-yellow axis marked 8% of the window as seed. It caught the four labeled seeds and also five blobs of blurred seeds, outside the focal plane, which in panel 3 appear with a dashed outline. The machine proposes, the person checks.
1 100 10,000 1 million −60 −40 −20 0 Otsu threshold, b* = −37.9 blue paper seeds blue-yellow color axis (b*), from blue on the left to yellow on the right
Real dataFigure 4. Histogram of the blue-yellow axis over the whole crop of this plate, 946 × 946 px, on a logarithmic scale. The paper makes the tall peak; the seeds make a long tail, not a second peak, because the blurred edges fill the middle. The Otsu threshold falls at b* = −37.9 and puts 5.2% of the crop pixels on the seed side.

The middle of the histogram is made of edge pixels, half seed and half paper. Moving the threshold one way or the other moves the entire edge of every seed, and it is this shift that matters in the instrument of the previous section. How the threshold is chosen, and what happens when the histogram has no valley, are in The threshold.

In SeedCounter, one of the methods is the click wave. You click on a seed, and a front grows from the click through pixels of similar color until it meets the color change at the edge. The threshold stops being one number for the whole image and is instead decided seed by seed, from the point the person chose. The math of the front is in The wave.

Before any threshold, the light has already decided part of the outline. A dark shadow touching the seed can pass the threshold and become seed, and a white reflection can open a hole in it. The math of the shadow is in the post Light decides the outline.

3 · Outline

The outline is a staircase of pixels

The threshold mask is a set of pixels. The outline is the boundary of that set: a sequence of edge pixels, each a neighbor of the next, that goes around the seed. In panel 3 of Figure 2, the orange pixels are that sequence, and the blue line is the edge it tries to represent.

Measuring the length of the staircase has a bias that can be calculated. Counting each straight step as 1 pixel and each diagonal step as √2, the sum exceeds the true perimeter by 5.5% on average over all directions: the factor is \(8(\sqrt{2}-1)/\pi = 1{,}0548\) [2]. In 1,904 rice grains from a published dataset, the measured ratio was 1.054052, within 0.07% of the calculation. The derivation is in The digital perimeter.

The outline that SeedCounter proposes becomes a polygon that the person checks and can correct point by point. Simplifying has a cost: the 48-sided outline overestimates circularity in seeds with low solidity, by 9.9% at the median. It has been measured, and the correction is the next step. The shape measures that come from the outline are in the Shape track.

line: √80 = 8.94 px chain: 4 + 4√2 = 9.66 px ratio 1.080
CalculationFigure 5. A line of slope 1/2 lights nine pixels. The chain that links them has four straight steps and four diagonal ones, 9.66 px against 8.94 px for the line: 8% more. In other directions the excess ranges from 0 to 8.2%, and the mean is 5.5%.

4 · Measurement

The numbers come from the outline

The area is the count of pixels inside the outline, times the area of one pixel. Length and width are Feret diameters: the larger is the greatest distance between two points of the seed, and the smaller is the smallest opening of a caliper that turns around it. The ratio between the two, the circularity and the solidity are combinations of these measures.

The table lists the four labeled seeds of Figure 3. Without a ruler in the crop, it stays in pixels, and that is why the ruler comes first. With the scale \(s\) in millimeters per pixel, length and width are multiplied by \(s\) and the area by \(s^2\).

Choosing a scanner or a camera changes the resolution and the route to the scale. A scanner at 1,200 dpi gives 47 px/mm, and ruler and seeds sit on the same glass. A camera 44 cm above the plate gives 40 px/mm over the whole plate, and the ruler has to be at the height of the seeds. The comparison is in the animation Scanner or camera.

SeedArea
(px)
Length,
max. Feret (px)
Width,
min. Feret (px)
C/L
11.80586,331,52,74
22.427104,533,03,17
31.53375,834,82,18
42.222105,929,73,56
Real dataTable 1. Measurements in pixels of the four labeled seeds of Figure 3, from the threshold mask. All four are labeled non-viable in the dataset.

Further reading

Five readings

  1. Otsu N. (1979). A threshold selection method from gray-level histograms. IEEE Transactions on Systems, Man, and Cybernetics 9(1), 62–66. doi:10.1109/TSMC.1979.4310076
  2. 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
  3. Joint Committee for Guides in Metrology (2008). JCGM 100:2008. Evaluation of measurement data: guide to the expression of uncertainty in measurement (GUM). doi:10.59161/JCGM100-2008E
  4. Tanabata T., Shibaya T., Hori K., Ebana K., Yano M. (2012). SmartGrain: high-throughput phenotyping software for measuring seed shape through image analysis. Plant Physiology 160(4), 1871–1880. doi:10.1104/pp.112.205120
  5. Whan A. P., Smith A. B., Cavanagh C. R., Ral J.-P. F., Shaw L. M., Howitt C. A., Bischof L. (2014). GrainScan: a low cost, fast method for grain size and colour measurements. Plant Methods 10, 23. doi:10.1186/1746-4811-10-23

Data

Figures 1 to 4 and Table 1: "Sementes de Orquídeas" dataset v8, Roboflow Universe (universe.roboflow.com/sementes-de-orqudea/sementes-de-orquideas), CC BY 4.0 license. Outlines in Figure 1 drawn from the dataset labels; threshold, mask, outlines and measurements in Figures 2 to 4 computed for this page. No millimeter scale.

Put a ruler in your image.

In SeedCounter, you mark the ruler, click on the seeds and check each outline. Measurements come out in millimeters.

Open SeedCounter