System designTroubleshooting

Stable blob area measurement: cut noise on a static object

Get a stable blob area measurement on a static part: why noise swings blob.area() from 980 to 3450 px and the fixes that hold the reading within a few percent.

LumaSpec Vision10 min read Share on LinkedIn

On this page 8 sections
  1. 01The number you should be reading
  2. 02Causes in order of probability
    1. 1. The bounding box is eating speckle (most likely)
    2. 2. The threshold sits on the noise floor
    3. 3. Auto exposure and auto gain are running
    4. 4. The light changes between frames
    5. 5. Focus, iris or mounting drift (least likely)
  3. 03Worked example: 980 to 3,450 px on one static part
  4. 04The noise floor no filter removes
  5. 05Checks before you trust the number
  6. 06When the usual answer is wrong
  7. 07Quick checklist
  8. 08Questions

A part sits still under the camera, yet blob.area() returns 980 px on one frame and 3,450 px on the next, and every distance you compute from the area moves with it. If you are building size or distance math on a smart camera or a PC pipeline, this fault stops the project until it is fixed. The diagnosis is short: the number you are reading is almost certainly a bounding-box area, and stray noise pixels are stretching that box from frame to frame. Below are the causes in order of probability, a one-minute test for each, the arithmetic that links area noise to distance error, and a 30-frame acceptance test that tells you when to trust the reading.

The number you should be reading

In machine vision, blob detection finds connected regions that differ from the background; the stability problem starts with which area you read from that region. A blob library can report two different quantities. The first is the bounding box: box width × box height, empty corners included. The second is the segmented pixel count: how many pixels the threshold actually marked as object. In several vision-sensor APIs the method blob.area() returns the box, and a second method, pixels(), returns the count. The blob analysis primer walks how both come out of the thresholded image, and bounding box area vs object area shows why they diverge.

One annotated frame settles which one you have. Draw the box the library reports on the live image for ten frames. If the box jumps to swallow a bright dot in a corner while the part is unchanged, you are reading the box. For distance math, read the segmented pixel count instead; measuring blob area by pixel counting gives the method.

Causes in order of probability

Cause Likelihood One-minute test Fix
blob.area() is the bounding box; speckle stretches it Highest Draw the reported box for 10 frames Read pixels(); open the mask
Threshold sits on the noise floor High Histogram cut lands near a peak Threshold midway between the peaks
Auto exposure or auto gain running Medium Log exposure and gain per frame Fix both values
Light output changes frame to frame Medium Gray patch mean over 30 frames 24 V DC drive, strobe or constant
Focus, iris or mount drifting Low Slow trend in the mean area Lock the iris, retighten mounts

1. The bounding box is eating speckle (most likely)

blob.area() multiplies box width by box height, so any noise pixel inside the stretched rectangle counts as part. A dot to the right of the part adds width; a dot below it adds height; the product of the two stretched sides is what you read. The fix has two steps. First, measure the segmented pixels with pixels(), which a distant speckle dot barely moves. Second, delete the speckle before labeling: a morphological opening, an erode followed by a dilate with a 3 × 3 kernel, removes one- and two-pixel blobs and leaves the part intact. Filtering before the threshold is the same order that cleans dust noise from screw thread images.

2. The threshold sits on the noise floor

If the segmentation cut lands within a few gray levels of the background, sensor noise flips pixels in and out of the blob every frame. Pull the histogram of the static scene: you want two separated peaks, one object, one background. Place the threshold midway between the peaks, not just above the background, because the midpoint leaves equal margin on both sides. Then write the value into the code as a constant; a threshold recomputed every frame rides the noise floor along with the pixels.

3. Auto exposure and auto gain are running

Auto exposure re-times the sensor each frame and auto gain rescales it, so gray levels slide under your fixed threshold and the segmented area breathes. Turn both off. Set a fixed exposure and a fixed gain that put the object peak near three quarters of full scale, then re-run the 30-frame test. If the API hides the value actually applied, read the actual exposure per frame instead of trusting the request. On color cameras, which pixels the auto algorithms meter decides whether they settle at all.

4. The light changes between frames

Mains-driven lighting modulates at twice the line frequency, and room light leaks into the scene as doors and people move; both slide the gray levels under a fixed threshold. Drive the illuminator from a 24 V DC supply at constant current, and strobe it when you also need to freeze motion. The wiring for strobe control when the camera has no flash output is its own guide. A diffused ring light from the ring lights range also flattens the brightness gradient across the part, which widens the margin around your threshold. The LS-RNG-0143 is a 100 mm ring light with a diffuser.

Ring lights100 mm dia. ring light with diffuser, 30° (LS-RNG-0143)LS-RNG-0143
Size
100-200 mm
Type
Diffused
Angle
30°
Voltage
24 V
$169.00View partBuild a system with it

5. Focus, iris or mounting drift (least likely)

With the part static, optics rarely explains a 3.5× swing, but an iris ring that creeps open changes both brightness and image scale, and a loose bracket wanders slowly. Set the aperture, tighten the iris lock, refocus for the sharpest edge gradient, and retorque the camera mount. A slow one-directional drift in the mean area points here; random scatter does not.

Worked example: 980 to 3,450 px on one static part

Inputs, straight from the bench: blob.area() returns 980 px on the quietest frames and 3,450 px on the worst, with camera and part fixed. Assumed part geometry: a compact blob whose box is 35 px wide and 28 px high, about 85 percent filled, giving 35 × 28 = 980 px of box and roughly 833 segmented pixels.

Rule in words: box area = width × height, and the box always grows to reach the farthest stray pixel.

A_box = width × height d ∝ 1 / √A → Δd/d ≈ ½ × ΔA/A

The arithmetic:

  • Quiet frame: 35 × 28 = 980 px.
  • Worst frame: one noise pixel 15 px beyond the right edge and 41 px below the bottom corner stretches the box to (35 + 15) × (28 + 41) = 50 × 69 = 3,450 px.
  • The part changed by nothing: 3,450 / 980 = 3.5, so two stray pixels multiplied the reading 3.5 times.
  • Distance consequence: distance follows 1 / √A, so those same frames imply distances differing by √3.5 ≈ 1.9 times. Unusable.

After the fix, reading pixels() with a 3 × 3 opening and locked exposure, gain and threshold, 30 frames of the same static part give 820 to 846 px around a mean of 833 px. Range = 26 px, and 26 / 833 = 3.1 percent. The distance error is about half the area error, or 1.6 percent. Decision: accept the station when the 30-frame range is under 5 percent of the mean; this one lands at 3.1 percent, so it ships.

The noise floor no filter removes

With everything locked, the boundary still moves: each pixel on the blob edge lands on one side or the other of the threshold as noise arrives. With about P pixels on the perimeter, a binomial estimate of the area jitter is σ ≈ √P / 2 pixels. The example blob has a perimeter near 2 × (35 + 28) = 126 px, so σ ≈ √126 / 2 ≈ 6 px, about 0.7 percent of its 833 px. For compact blobs this floor scales with the fourth root of the area: a 100 px blob carries a floor past 3 percent, a 10,000 px blob about 0.1 percent. Keep the part above roughly 1,000 segmented pixels and the floor stays under 1 percent.

A part that fills too few pixels cannot be filtered into stability. Check what sensor and field of view deliver the pixels you need with the camera resolution calculator.

Camera resolution for the smallest feature
Units
Pixels needed
–
Sensor size
– MP
Smallest sensor that fits
–
Pixel on the part
– mm
Pixels across the feature, that sensor
–

Pixels needed = field / feature × pixels per feature on each axis (field incl. margin). The lens must resolve the pixels too: Nyquist = 1000 / (2 × pixel µm) lp/mm.

Find cameras with enough pixels Open the full calculator

The LS-CMR-0166 is a 12 MP USB3 area scan camera with a 4000 × 3000 resolution. Over a 400 mm field of view that is 10 px per mm, so a 3.5 mm part spans the 35 px of the worked example and carries the same 833 px region. More sensors and mounts are in the area scan cameras range.

Area scan cameras12 MP USB3 area scan camera, IMX226, 1/1.7" rolling shutter, 30 fps, 4000 × 3000 resolution (LS-CMR-0166)LS-CMR-0166
Sensor format
1/1.7"
Interface
USB3
Resolution
12 MP
Shutter
Rolling
$560.00View partBuild a system with it

Checks before you trust the number

  1. Capture 30 frames of the static part and log the segmented pixel count each frame.
  2. Compute (max − min) / mean. Accept under 5 percent; retune between 5 and 10 percent; above 10 percent, or any jump of several times, go back to cause 1.
  3. Annotate one frame with the reported box and the segmented mask; no stray dots inside the box.
  4. Check two separated peaks in the histogram and the threshold set midway, as a constant.
  5. Check exposure and gain are fixed, not automatic, and identical on every frame.
  6. Check the illuminator runs on 24 V DC, constant or strobed, with ambient light out of the frame.

Running the inspection on the device removes one more source of drift, because the settings that produced the image are the settings the analysis uses. The LS-SMC-0063 is a 1.6 MP smart camera with a 16 mm lens and its own white light source. The full range of smart cameras runs the same checks on-device.

Smart cameras & vision sensors1.6 MP smart camera, 60 fps, 16 mm lens, white light (polarized, transparent light) (LS-SMC-0063)LS-SMC-0063
Interface
GigE
Resolution
Up to 3 MP
$1,110.00View part

When the usual answer is wrong

If your library already returns the pixel count from its area method, skip cause 1: a 3.5× swing is then threshold or lighting, and causes 2 through 4 own it. When the speckle is the product, such as particle or defect counting, do not open it away; measure each blob separately and count blobs instead of stretching one box. A rolling-shutter camera under mains-frequency room light shows bands that travel down the frame, flipping threshold pixels as they go; DC illumination or a shroud ends it. And separate noise from real change: random scatter around a flat mean is noise, a steady one-directional trend is a real change in the part or the mount, and no filter should hide it. The stability-first order used here, light then lens then exposure then code, is the one behind stable 2D vision inspection systems.

Quick checklist

  • Read pixels() for any area that feeds math; keep blob.area() for presence and coarse position.
  • Open the binary image with a 3 × 3 kernel and keep the largest blob before measuring.
  • Threshold midway between the two histogram peaks, written as a constant.
  • Exposure and gain fixed; log the applied values once to confirm.
  • Illumination on 24 V DC, constant or strobed; ambient blocked.
  • Ship when the 30-frame range is under 5 percent of the mean.

If the spread stays above 5 percent after these fixes, the fastest next step is a second pair of eyes on one annotated frame plus the 30-frame log: send both through the contact page. Rebuilding the station instead? The camera finder, the lighting finder and the configurator assemble it in order.

Questions

Why does blob area change when the part is not moving?

Because `blob.area()` is the bounding box: box width × box height. A noise pixel outside the part stretches the box in both directions at once, and the product grows fast. 15 px of extra width plus 41 px of extra height turns 980 px into 3,450 px. The part never moved; the rectangle did. Count the segmented pixels and a distant speckle dot adds almost nothing.

How do I test which quantity my library returns?

Pass it a synthetic diagonal shape. A 45-degree line 100 px long has a bounding box near 100 × 100 = 10,000 px but only about 100 segmented pixels. A method that reports near 10,000 is the box; near 100, the pixel count. On a real part, one annotated frame answers the same question in a single capture.

How much frame-to-frame spread should I accept?

Capture 30 frames with the part static, log the segmented pixel count, and compute (max − min) / mean. Under 5 percent, trust it for distance math. Between 5 and 10 percent, tighten the threshold margin and the lighting first. A jump of several times is not jitter at all: it is a bounding box stretched by speckle, so change what you measure, not how you average.

Does averaging several frames fix it?

Averaging the pixel count over N frames cuts random jitter by about 1 / √N, so 9 frames leave a third of the noise. It does nothing when the error is a box stretched by speckle, because that error appears on every frame the same way. Fix the measurement first; average afterwards only if you need the last few tenths of a percent.

When is bounding-box area the right measurement?

Use the box for presence checks, counting, and axis-aligned rectangular parts whose fill factor never changes. Use the segmented pixel count for anything that feeds distance or size math: the box counts empty corner pixels the part does not occupy and reacts to any stray blob in the field. If you must keep the box, keep only the largest blob before you measure it.