System designHow-to

Measure distance between two glare points in an image

Measure the distance between two glare points: threshold highlights, take centroids, pair the nearest centroids, convert pixels to millimetres with your scale.

LumaSpec Vision9 min read Share on LinkedIn

On this page 10 sections
  1. 01What you need
  2. 02Fix the pixel scale first
  3. 03Light the part so each set shows two clean points
  4. 04The procedure, in six steps
  5. 05Worked example: ten glare-point pairs at 0.025 mm per pixel
    1. The arithmetic
    2. The decision
  6. 06Pairing traps that corrupt the distances
  7. 07Verify the numbers before you report them
  8. 08When centroid-to-centroid is not the right measurement
  9. 09Before you order the hardware
  10. 10Questions

Shiny parts report their own dimensions in light: two glare points appear where the surfaces throw your illumination back into the lens, and the span between them is a measurable number. This walkthrough is for anyone who has to turn that span into millimetres across many sets in one image — ten pairs of highlights on connectors, balls or polished pins, for example. You will calibrate the pixel scale, threshold and label each highlight, take blob centroids, pair each centroid with its nearest neighbour, and convert the result to millimetres. The worked example carries a full set of numbers, arithmetic included.

What you need

A working set-up needs four pieces:

  • Camera and lens covering the part with margin on every side, so no glare point ever sits against the frame edge.
  • A small, bright light placed where the reflection geometry wants it — for small shiny parts, one of the spot lights aimed at the specular angle does the job.
  • A calibration standard in the part plane: a stage micrometer, a steel ruler, or any gauge with two edges a known distance apart.
  • Vision software with thresholding, connected-component labelling and a centroid function — every blob-analysis library carries all three.

Keep the working distance mechanically fixed. Any drift rescales your millimetre-per-pixel value, and no software fixes that after the fact.

Fix the pixel scale first

Everything you report is pixel count times scale, so measure the scale before anything else. Image the calibration standard at the exact working distance the parts will use, measure a known span in pixels, and divide:

scale (mm/px) = known span (mm) / same span measured (px) distance (mm) = centroid separation (px) × scale (mm/px)

There is a calculated route too: divide the sensor pixel pitch by the lens magnification. A 5 µm pixel behind a 0.4x lens images 5 µm ÷ 0.4 = 12.5 µm = 0.0125 mm of part per pixel. The object-space pixel size calculation works that route in full.

A fixed-magnification lens turns the scale into a datasheet value instead of a derived one:

Machine vision lensesFixed-magnification lens, 0.4x, 227 mm WD, 1.2" (LS-TCL-0574)LS-TCL-0574
Sensor format
1.2"
Mount
C-mount
Image circle
16-22 mm
$2,269.00View partBuild a system with it

Still choosing optics? Work backwards: decide the field you need to see, then let the focal length calculator narrow the candidates for your sensor and working distance.

Lens focal length, field of view and working distance
Units
Solve for
Focal length
– mm
Field of view
– mm
Working distance
– mm
Magnification
– x
Angle of view
– °
Pixel on the part
– mm

Thin-lens model: m = sensor width / field of view, f = WD × m / (1 + m). Accurate to a few percent above about 150 mm; check the lens's minimum object distance.

Find lenses with this focal length Open the full calculator

Light the part so each set shows two clean points

Where a glare point lands follows the law of reflection — the bright field versus dark field choice is the same geometry applied to whole surfaces. Three habits keep glare points measurable:

  • Small source, not diffuse. A small source images as a tight highlight; a broad diffuse panel smears each point over many pixels and invites merges. The focused-versus-diffused trade is compared in LED lens beam shaping: focused versus diffused illumination.
  • Saturated points, dark surround. Set exposure so the pair sits well above threshold while neighbouring surfaces stay below it.
  • Rigid geometry. On a curved surface the highlight slides as the part or light moves, so mount both rigidly and inspect in a repeatable pose.

When motion or ambient light forces a short exposure, a small bright source keeps the highlights saturated anyway:

Spot lights6 mm High luminance spot light, power 5 W (LS-SPT-0175)LS-SPT-0175
Size
Under 50 mm
$229.00View partBuild a system with it

The full spot light range, filterable by size, wavelength and included lens:

LightingSpot lights

Small fields and coaxial lenses

191 models · from $109.00

The procedure, in six steps

One definition first: a set is the pair of glare points belonging to a single feature, and each set yields one distance.

  1. Calibrate. Image the calibration standard at the working distance, measure a known span in pixels, and record the scale in mm/px with the date and target used.
  2. Acquire. Shoot the parts at that same working distance, with exposure set so glare points saturate and the background stays below threshold.
  3. Threshold. Start near the top of the histogram: on an 8-bit image, gray level 200 of 255 is a usual first value for saturated highlights. If a point splits into fragments, drop the threshold 10 at a time; if two points fuse, raise it.
  4. Label and filter. Run connected-component labelling, log every blob's area, then keep only blobs inside a gate set around the area peak. Highlights a tenth to four tenths of a millimetre across land near 10 to 200 px of area at 0.025 mm/px.
  5. Find centroids. Compute each blob's intensity-weighted centroid with your library's moments call (cv2.Moments() in OpenCV). Centroid-to-centroid is the repeatable choice: a bounding-box corner jumps a whole pixel when the threshold moves, while the centroid shifts sub-pixel.
  6. Pair and convert. For each centroid, find the nearest other centroid, record the pixel distance, multiply by the scale, and report one result per set.

Step 4 doubles as the count check: ten sets must end as exactly twenty blobs.

Worked example: ten glare-point pairs at 0.025 mm per pixel

One image, ten sets, two points per set — the case this how-to targets. The inputs, each with its origin:

  • Scale: on the calibration target, a 0.05 mm graduation spans 2 px, so the scale is 0.05 ÷ 2 = 0.025 mm/px.
  • Threshold: gray level 200 of 255, confirmed by zoom inspection — twenty blobs, no fragments.
  • Area gate: 10 to 200 px, read off the logged area distribution.
  • Measured separations: the ten centroid-to-centroid distances came out between 38 and 42 px, mean 40 px.

The arithmetic

The rule is the one from the formula block: distance in millimetres equals separation in pixels times the scale.

  • Mean: 40 px × 0.025 mm/px = 1.0 mm.
  • Range: 38 px × 0.025 mm/px = 0.95 mm; 42 px × 0.025 mm/px = 1.05 mm.
  • Uncertainty: at half a pixel of centroid repeatability, ±0.5 px × 0.025 mm/px = ±0.0125 mm, call it ±0.013 mm.

The decision

A common rule for gauges is to keep measurement uncertainty at or below a quarter of the tolerance. Against a ±0.05 mm specification, a quarter is ±0.0125 mm — this set-up sits exactly at that ceiling, so it passes. Against a ±0.02 mm specification it does not: double the magnification instead. At 0.0125 mm/px, the same ±0.5 px is ±0.006 mm, under a third of ±0.02 mm (0.020 ÷ 3 ≈ 0.0067 mm), and the quarter rule clears with room to spare.

Pairing traps that corrupt the distances

Nearest-neighbour pairing only holds when the two points of a set sit closer to each other than to any other point in the image. The failure modes, most common first:

  • Fused pair. Both points merge into one blob: nineteen blobs, no valid distance for that set. The count check catches it, and the area log shows one blob near double the typical area.
  • Split point. A threshold set too high breaks one highlight into fragments that pass a too-low gate and pair with each other at a distance near zero. The area distribution shows two peaks instead of one — retighten the gate or drop the threshold.
  • Cross-set pairing. When two sets sit closer together than the spacing inside a set, nearest-neighbour pairs across sets. Cluster the centroids into sets first, or space the parts in the fixture so within-set spacing is always the smallest distance present.

Verify the numbers before you report them

  • Repeat frames. Ten acquisitions of a still part: every reported distance should stay within half a pixel of the others. A wider spread points to light flicker or threshold chatter.
  • Move the part. Shift and rotate a part within the field. The set distance must not move beyond your uncertainty; if it does, the scale or working distance drifts, or the highlight slides on a curved surface.
  • Measure a known gap. A gauge with a known separation must land inside the uncertainty you claim.

The same discipline is laid out for general point-to-point work in Measure planar distances with a calibrated camera, and when half a pixel is not repeatable enough, the invert-and-weigh technique in Grayscale centroid of a dark circle: invert for sub-pixel pushes the centroid below it.

When centroid-to-centroid is not the right measurement

  • Transparent spheres. In droplet or ball-lens work the two highlights form by reflection at the front surface and refraction through the rear, so converting their separation to a diameter takes the sphere's optics, not just the pixel scale. Build that conversion deliberately before trusting a number.
  • Points at different heights. If the two surfaces sit at different depths, perspective shifts one centroid relative to the other. A telecentric lens removes the magnification change across depth; otherwise keep both points in one plane.
  • Ordered features. Marks that run in sequence along a part — crack tips, a row of hole centres — are a pairing problem of a different shape; How to measure crack endpoint distance from an image handles the ordered case.

For the plain two-points-per-set case, nearest-neighbour pairing with the count check is the whole algorithm.

Before you order the hardware

  • Field of view: the part set plus 10-20% margin per side, so no glare point can touch the frame edge.
  • Scale before purchase: divide pixel pitch by magnification and check the result against the quarter-of-tolerance rule from the worked example.
  • Light: a small source bright enough at your shortest exposure; the light finder filters by size and wavelength, and the configurator steps through a full build around your camera.
  • Rigid mounting: light, camera and fixture on one base — highlight positions are geometry, and geometry that moves measures nothing.

More scale-and-measure recipes sit on the systems topic page. If your part is transparent, steeply curved or moving faster than a short exposure can freeze, describe the geometry through the contact page before machining a bracket — the fix is usually one lighting or magnification choice.

Questions

Why does a shiny sphere show two glare points instead of one?

One small light reflected by a smooth opaque surface gives a single highlight, at the point where the surface angle sends the light into the lens. A second point appears when the part is transparent and light also returns through the rear surface, or when a second, mirrored light adds its own reflection. Either mechanism places the pair symmetrically about the part's axis, which is what makes the separation worth measuring.

Do I need to recalibrate after changing the working distance?

Yes. The mm/px scale is proportional to magnification, so any focus or distance change rescales every result. A 10% working-distance increase makes a true 40 px separation span only about 36 px; at the old 0.025 mm/px scale that reads as a false 0.91 mm instead of 1.0 mm. Re-shoot the calibration target whenever focus is touched, and record the scale with its date and target.

How repeatable is a centroid-to-centroid distance on a still part?

For a symmetric, saturated blob, the intensity-weighted centroid holds well inside half a pixel between frames, and sub-pixel grayscale methods go lower still. The larger error is usually the scale: working-distance drift rescales every result directly. Lock focus and distance mechanically, re-shoot the calibration target after any adjustment, and quote uncertainty as the combination of both.

The two glare points merge into one blob — what do I change first?

Reduce exposure time or light drive current until the dim bridge between the points drops below threshold, while the points themselves stay saturated. A smaller light source also narrows each highlight; a diffuse panel widens them. If the optics cannot separate them, raise the magnification so the pair spans more pixels, then confirm the blob area distribution shows one tight peak again.

Can I measure the sets on parts moving down a belt?

Yes, if the exposure freezes the motion. Keep blur under half a pixel: at 0.025 mm/px that is 0.0125 mm of travel, so a belt at 1 m/s allows about 12 µs of exposure (0.0125 ÷ 1000 mm/s). Exposures that short normally need a strobed or overdriven light, and the parts must present the same pose each pass for the reflection geometry to hold.