A laser triangulation set-up gives you a bright red line, and the bump where a droplet sits is clearly visible. The problem is everything around the bump: speckle, scattered points and a thick, ragged line. Before you can measure droplet height you need one reliable line position per image row. This guide shows a fast, robust way to clean laser line extraction noise out of the raw image, then how to check the set-up so the extraction has something clean to work with. It complements the calibration checks for a tilted laser triangulation point cloud, which cover what happens after the line is already clean.
What you need
- A line laser and a camera viewing the laser plane at an angle, typically 30 to 60 degrees off perpendicular.
- A machine vision camera fast enough for your line rate; a 6 MP GigE area scan camera with a C-mount is a common starting point for a bench set-up.
- Your image processing library of choice with connected-component and morphology functions.
- Two calibration references: the bare surface, and a gauge block or shim of known height.
If the measurement matters commercially, compare this build-from-parts route with a purpose-built unit such as the MIS-DP3850-01P 3D laser profile sensor, where laser, optics and calibration are matched at the factory and the height profile comes out of the SDK directly.
Step 1: get the line dominant in the image first
Every cleanup step gets easier when the laser is the brightest thing in the frame. Work through these checks before writing code:
- Darken the cell or enclose the station so ambient light cannot dilute the line.
- Raise exposure until the line core is near but not at saturation; a clipped core widens your measured line.
- Add a band-pass filter matched to the laser wavelength if ambient light cannot be fully removed.
- Square the camera to the laser plane so the line runs vertically in the image. A tilted line breaks any per-row logic.
- Check the laser focus: a sharp line over the full working distance beats a bright, blurry one.
Step 2: isolate the line blob with connected components
Speckle shows up as small islands away from the main line. Threshold the red channel or a red-dominance ratio (red minus the average of green and blue), then label connected components and keep only those inside a size range. The main line is typically thousands of pixels; speckle islands are a few dozen.
Keep components whose pixel count is above roughly 1 percent of the largest component's area, or whose bounding box spans at least half the image height. Everything else is noise and gets zeroed. This single step removes most scattered points before you touch the line itself.
Step 3: extract one position per row
With the blob isolated, compute the line position for every row it spans. Two options:
- Centroid method (best accuracy). For each row, take the pixels of the surviving blob in that row and compute the intensity-weighted average x position. This uses the whole line profile and gives sub-pixel resolution.
- Edge method (fastest). For each row, take the left-most or right-most pixel of the blob. This works when the line is vertical and you only need the profile edge, but it is noisier because a single stray pixel moves the result by a full pixel.
Restrict both methods to the blob's bounding box so you never scan empty rows. On a typical 2 MP region of interest the centroid pass runs in well under a millisecond per frame on a desktop CPU.
Step 4: clean the extracted profile, not the image
After extraction you have an array of x positions, one per row. Clean that array, which is far cheaper than cleaning pixels:
- Compute the median of the positions; on a flat surface this is your baseline.
- Reject any row whose position deviates from a local median by more than a few pixels, unless you expect real features there.
- For the feature region, apply a small median filter (window of 3 to 5 rows) to smooth speckle-driven jitter without rounding off the droplet peak.
- Optionally fit a line to the flat portions and subtract it, which removes any residual tilt.
Here Δx is the line shift in pixels at the droplet peak relative to the baseline, s is the millimetre-per-pixel scale, and θ is the angle between the camera axis and the laser plane. With a 45 degree set-up, tan(45°) = 1, so height in millimetres is simply the pixel shift times your scale.
Step 5: a worked example
Suppose your set-up images a 40 mm wide field on a 2448 pixel sensor, so s = 40 / 2448 ≈ 0.0163 mm per pixel. The camera views at 45 degrees. On the droplet peak the extracted line shifts 22 pixels from the baseline. Then:
h = 22 × 0.0163 / tan(45°) ≈ 0.36 mm.
Calibrate s the honest way: capture a gauge block of known height, measure the pixel shift, and back out the effective scale including the angle. If a 1.00 mm block shifts 60 pixels, your effective scale is 1.00 / 60 ≈ 0.0167 mm per pixel of height, and you no longer care whether the mount is exactly at 45 degrees.
Step 6: morphology, used sparingly
Erosion followed by dilation (an opening) removes thin speckle bridges; closing fills small gaps where the line breaks. Use a 3×3 kernel and at most one or two iterations. Over-morphing widens the line and blunts the droplet peak, which directly biases your height. As a rule: threshold, keep the big components, extract the centroid, and only reach for morphology if gaps or bridges remain.
Choosing parts for the imaging side
If you build the triangulation head from components, the camera choice drives everything else. Browse the 3D sensors range for factory-calibrated profilers, or the area scan cameras range for a build-it-yourself head. Use the camera finder to filter by interface and resolution, and the system configurator to match camera, lens and mount before ordering. For help choosing, the machine vision lens selection guide covers the field-of-view and working-distance trade-offs that determine your scale factor.
A ready-made profiler sidesteps most of this article: the MIS-DP3850-01P returns a calibrated height profile, so steps 2 to 5 collapse into an SDK call. The DIY route wins when you need an unusual field of view, a custom wavelength, or a very low component count.
Checks before you trust the measurement
Run this list on every new set-up:
- [ ] Line is vertical within a degree, or you have measured the tilt and corrected for it.
- [ ] Laser core near saturation, background well below threshold.
- [ ] Flat-surface baseline is straight: residual drift under a pixel across the field.
- [ ] Gauge block reads its true height to within your tolerance.
- [ ] Droplet measurement repeats within a pixel of shift across ten captures.
- [ ] Extraction runs fast enough for your line rate with margin.
When the usual answer is wrong
Clear or moving droplets scatter light and can split the line into two reflections, one off the surface and one off the liquid. Connected components will then keep the wrong blob. If the part is wet, glossy or curved, a single-camera triangulation line may not be the right tool at all: a 2.5D inspection system or a height measurement based on multiple angles is often more robust. And when noise keeps returning after every cleanup, revisit lighting before code — the glass bottle defect detection guide makes the same point in a different domain: fix the image first, threshold second.
Once the height line is trustworthy, the next stage is turning per-frame profiles into a stored, comparable 3D model, which the voxel grid storage guide covers. If you need help specifying the camera and laser for your droplet or bead measurement, contact us — expert support comes with every order.
Quick reference
- Fix the image first: dark cell, saturated line, narrow filter, vertical line.
- Threshold, keep components above ~1 percent of the largest, extract per-row centroids.
- Clean the position array with a median baseline and a 3 to 5 row median filter.
- Calibrate scale with a gauge block instead of trusting the mounting angle.
- Verify with a known height before believing any droplet number.
Questions
Why does my laser line look broken and speckled in the image?
Common causes are a low line-laser power relative to ambient light, a short exposure that starves the sensor, surface scatter from glossy or wet spots, and dust or reflections along the path. Raise the laser power or exposure until the line is close to saturation, darken the cell, and fit a narrow band-pass filter matched to the laser wavelength before touching any code.
How do I convert the extracted line position to droplet height?
You need the triangulation angle and a scale factor. Calibrate by capturing the flat surface with no part, then a gauge block of known height, and measure how many pixels the line shifts. Height equals pixel shift multiplied by the scale factor divided by the sine or tangent term of your viewing angle. Two calibration captures remove the guesswork.
Should I use connected components or row-wise extraction for the line?
Use connected components when speckle is severe: keep the largest blob per region, then read one position per row inside its bounding box. Use plain row-wise extraction, such as the intensity-weighted centroid of the brightest run, when the line is already dominant and you need maximum speed. Many systems do components once for cleanup and centroids after.
Does the laser line have to be exactly vertical in the image?
For row-wise methods, yes, or nearly so. A tilted line means one image row can contain several points of the profile, so the per-row logic picks the wrong edge. Either square the sensor to the laser plane mechanically, or measure the tilt and rotate the image, or switch to a column-scan that follows the line's angle.
Is a ready-made 3D laser profiler easier than building it from parts?
Usually yes when the measurement must be trustworthy. A profiler ships with the laser, imaging optics, triangulation geometry and calibration already matched, so the height comes out of the SDK instead of your own geometry math. Building from an area scan camera and a line laser pays off only for unusual fields of view or tight budget or space limits.