ApplicationsApplication note

Real-time segmentation of a metal part on a lathe

Real-time segmentation of a metal part on a lathe: exposure math to freeze rotation blur, lighting against specular streaks, and a per-frame threshold chain.

LumaSpec Vision11 min read Share on LinkedIn

On this page 9 sections
  1. 01The image is for surface state, not cut progress
  2. 02What rotation actually blurs
  3. 03Pixel scale, frame rate and the spindle trigger
  4. 04Lighting geometry: beat the specular streak
  5. 05The per-frame segmentation chain
  6. 06Frame-to-frame comparison: wear, swarf and over-cut
  7. 07Pitfalls on a live machine
  8. 08Set-up checklist and the decision
  9. 09Questions

A shiny cylinder spinning at 3000 rpm looks like a hard segmentation problem, and it mostly is not: it is an exposure and lighting problem with a simple threshold on top. Once the image is stable from frame to frame, thresholding plus a little morphology separates the part from the machine interior in a few milliseconds on a PC. The sections below give the numbers for adding in-process inspection to a lathe — part presence, swarf, tool wear, surface finish — and show where the image beats the spindle clock, and where it does not.

The image is for surface state, not cut progress

The lathe's controller already knows where the cut stands: programmed depth, feed rate and elapsed time give it progress no camera will match. Do not spend a vision system re-deriving that number. The image earns its keep where the clock is blind: whether a chip is forming or the tool is rubbing; whether swarf is wrapping the workpiece; whether the finish stays consistent through the pass; whether the part is still seated in the chuck.

Those split into two jobs with very different exposure budgets. Silhouette jobs — presence, swarf wrap, diameter — run at ordinary exposures. Surface jobs — wear, chip form, finish — need the microsecond budget worked out below, about two hundred times shorter.

What rotation actually blurs

A point on the surface moves at the surface speed, and during the exposure it streaks across the sensor by speed times time:

v = π × D × n (surface speed, mm/s) blur = v × t (travel during exposure, mm) t_max = p / v (exposure for one pixel of blur, s)

D is the part diameter, n the spindle speed in revolutions per second, t the exposure time, and p the image scale in millimetres per pixel at the part.

Worked example: a Ø40 mm steel shaft at 3000 rpm, imaged by a 1600 × 1200 pixel camera over a 48 mm wide field.

  1. Spindle speed: n = 3000 rpm ÷ 60 = 50 rev/s.
  2. Surface speed: v = π × 40 mm × 50 s⁻¹ = 6,283 mm/s ≈ 6.3 m/s.
  3. Image scale: p = 48,000 µm ÷ 1,600 px = 30 µm per pixel.
  4. Surface detail: t_max = 30 µm ÷ 6,283 mm/s = 4.8 µs. A 100 µs exposure streaks the surface 6,283 mm/s × 0.0001 s = 0.63 mm, about 21 pixels, and a 0.2 mm tool mark smears into its neighbours.
  5. Silhouette: a cylinder rotating about its own axis puts its outline on the same pixels every frame, so rotation blurs the part-to-background boundary by exactly zero. A 1 ms exposure segments the part cleanly, as long as the light holds a steady level.

The decision in one line: silhouette checks run at ordinary exposures; anything that reads the surface needs an exposure, or a flash pulse, of about 5 µs at this speed — scaled on your machine as p ÷ v.

The two jobs side by side:

Silhouette job Surface job
Answers part present, swarf wrap, diameter tool wear, chip form, finish, marks
Exposure 1 ms class, set by light level t_max = p ÷ v — 4.8 µs in the example
Lighting broad diffuse grazing dark field
Shutter either type global
Trigger optional spindle index pulse
Method fixed threshold + blob threshold + frame differencing

Pixel scale, frame rate and the spindle trigger

Size the pixels from the smallest surface feature you must resolve. A tool mark of 0.2 mm needs at least 3 pixels across, so p ≤ 0.2 mm ÷ 3 ≈ 0.067 mm per pixel; at the worked example's 30 µm per pixel, that mark shows with about 7 pixels of support and a 0.5 mm chip fragment with about 17. The camera resolution calculator runs this the other way, from a field of view and a smallest feature to a pixel count.

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

Frame rate then meets the spindle. At 50 rev/s, one revolution takes 20 ms. A 30 fps camera repeats every 33.3 ms, or 1.67 revolutions, so each free-running frame lands roughly 240° further around the surface. That is fine for accumulating statistics and useless for watching one spot wear. Trigger the exposure from the spindle index pulse instead: every captured frame then shows the same angular station, skipped revolutions cost nothing, and frame-to-frame differences become meaningful.

Processing cost scales with pixels. The worked example's full frame is 1600 × 1200 = 1.92 MP; a 200 × 200 pixel ROI at the tool station is 40,000 pixels, about 2% of it. Crop to the job and even a modest processor keeps pace with 30 fps.

Lighting geometry: beat the specular streak

Ground steel returns light two ways: a diffuse component that follows the geometry, and a specular streak that follows the light source. The streak is what breaks naive thresholding — one frame it sits inside the part, the next it straddles the boundary, and a global threshold carves the image along the highlight instead of along the edge. Both cures are geometric; lighting geometry for image contrast works the trade in general.

Broad diffuse light, for silhouettes. Wrap the shaft in even illumination so the metal reads uniformly bright against the dark machine interior and the boundary becomes a clean brightness step. A diffused bar light mounted close does this; the same choice on turned connectors is worked through in lighting shiny metal pins without glare.

Grazing dark field, for surface detail. Lay a bar light nearly parallel to the surface, roughly 10° to 30° above it. Tool marks, chips and scratches scatter light back to the camera while flat metal reflects it past the lens, so the image is dark metal with bright defects — the defects become the blobs you threshold.

Bright-field and dark-field lighting geometry High-angle light reflects off the flat surface straight into the lens, so the surface looks bright. Low-angle light reflects away from the lens, so the surface looks dark and only edges or scratches scatter light upward.flat part with a scratchCamerabright field(high angle)dark field (low angle)flat areas reflect away;only the scratch sends light up
Bright-field and dark-field lighting geometry. High-angle light reflects off the flat surface straight into the lens, so the surface looks bright. Low-angle light reflects away from the lens, so the surface looks dark and only edges or scratches scatter light upward.

If a streak survives both, cross-polarize: polarizing film over the light and an analyzer on the lens removes the specular return, at the price of lost light that you pay back with more illumination or gain. Copper surface inspection lighting shows the technique end to end.

The LS-BAR-1276 is a 372 × 28 mm white diffused bar light on 24 V; mounted above and slightly back from the shaft, it plays the diffuse role. The LS-BAR-0400 is a 312 × 30 mm high luminance bar light on 24 V; laid at a grazing angle along the workpiece, it plays the dark-field role.

Bar lightsBar light, 372 x 28 mm, White (LS-BAR-1276)LS-BAR-1276
Size
200-400 mm
Type
Diffused
$439.00View part
Bar lights312 x 30 mm High luminance bar light (LS-BAR-0400)LS-BAR-0400
Size
200-400 mm
Type
Standard
$459.00View part

The per-frame segmentation chain

With exposure and lighting settled, the algorithm should be deliberately plain — plain survives on a machine tool.

  1. Threshold. With strobed lighting, teach one fixed gray level from a known-good part; every frame is then lit identically and a fixed level is the fastest, most repeatable option. Where reflectivity drifts from pass to pass, recompute a global level per frame with Otsu's method. Where ambient shop light or coolant sheen shifts the background, a local-mean adaptive threshold holds the boundary — see also dark region extraction with adaptive thresholding.
  2. Clean up. An opening — erosion then dilation with a 3 × 3 structuring element — removes single-pixel speckle from coolant droplets and chips in flight; fill holes to close the silhouette.
  3. Decide. Blob analysis returns area, centroid and bounding box per region. The Ø40 mm silhouette spans about 1,333 pixels at this scale, so anything under a few hundred pixels is debris, not part; count lines per region with blob analysis shows the plumbing.
  4. Measure. For diameter or taper, run a sub-pixel edge operator along several scan lines across each silhouette edge and fit straight lines; a circle fit at the chuck end also catches runout. On a clean, high-contrast edge, sub-pixel interpolation repeats to about 0.1 pixel, which is 3 µm at this scale. On a running lathe, plan on ±0.02 to ±0.05 mm for a Ø40 mm diameter once vibration and coolant join in.

Cameras that fit the two jobs: the MV-SCA002M-03S-WBN-SR is a 0.3 MP mono vision sensor with its 3 mm lens preset to focus at 240 mm — global shutter, Fast Ethernet, M5.8 mount, few enough pixels that latency stays trivial. The HK-TD032-12-WBN pairs a 1.6 MP mono sensor with a 1/2.9" global shutter behind an M12 mount, for surface work at a higher pixel density. The MV-CU020-90GC is a 2.5 MP GigE camera with a 1/1.7" global-shutter GMAX4002 sensor on a C-mount, for when you want free choice of lens. More sit in the smart camera and area scan camera categories.

Smart cameras & vision sensorsHikrobot MV-SCA002M-03S-WBN-SR SCA vision sensor, 0.3 MP, Mono, 3 mm lens, Focus distance 240 mmMV-SCA002M-03S-WBN-SR
Interface
Fast Ethernet
Resolution
Up to 3 MP
$1,989.00 · quotedView and quote
Smart cameras & vision sensorsHikrobot HK-TD032-12-WBN 1.6 MP mono vision sensorHK-TD032-12-WBN
Interface
Fast Ethernet
Resolution
Up to 3 MP
$1,699.00View part
Area scan camerasHikrobot MV-CU020-90GC 2.5 MP Area Scan Camera, GigE, GMAX4002, ColorMV-CU020-90GC
Sensor format
1/1.7"
Lens mount
C-mount
$309.00View part

Frame-to-frame comparison: wear, swarf and over-cut

With index triggering, segmentation turns into change detection nearly for free. Keep the binary mask of a known-good pass as a reference and compare each new mask against it; flag the part when the mismatched pixel fraction crosses a level you set. On the 40,000-pixel tool-station ROI, a 2% mismatch is 800 pixels — far above sensor noise, far below a visible defect being missed.

Patterns tell you which problem you have: new foreground growing near the tool position is chip buildup or a built-up edge; new foreground outside the expected silhouette is swarf starting to wrap; silhouette width shrinking faster than the programmed depth of cut predicts is a tool pulling in or an over-cut. Refresh the reference whenever a part passes inspection, so slow tool wear shows as a trend rather than a jump.

Pitfalls on a live machine

  • Coolant and mist. Droplets on the window read as blobs, and mist softens contrast. Blow the window clean with an air wipe or mount behind the machine's splash shield, and discard regions that touch the ROI border.
  • Shop-light flicker. Mains-driven lighting modulates at twice the mains frequency — 100 Hz on a 50 Hz supply — so millisecond exposures land on different parts of the cycle and the threshold drifts. Microsecond exposures do not care; for silhouette work, strobe the inspection light so every frame sees the same pulse. Camera flicker under artificial lighting walks the diagnosis.
  • Auto exposure hunting. Auto exposure re-aims between frames and drags your threshold with it. Fix the exposure at the computed t_max; if you must leave auto on, cap it — capping the maximum auto exposure time shows how.
  • Rolling shutter versus short flash. A flash short enough to freeze the surface speed lights only the sensor lines being read at that instant; a flash long enough to cover the whole readout reintroduces blur. When the budget drops below a few hundred microseconds, choose a global shutter.
  • Vibration. Camera shake blurs the image by the same speed-times-exposure rule, now with the relative speed between camera and part. Bolt the bracket to the machine base, keep it short and stiff, and re-check the image scale after any crash.

Set-up checklist and the decision

Work the numbers in this order and the hardware picks itself:

  1. Measure the part diameter D and the spindle speed n of the pass you must inspect.
  2. Compute v = π × D × n (6.3 m/s for the Ø40 mm example at 3000 rpm).
  3. Pick the smallest feature to resolve and set p ≤ feature ÷ 3 (p ≤ 0.067 mm per pixel for 0.2 mm marks).
  4. Compute the exposure budget t_max = p ÷ v (4.8 µs in the example). This is the moment you learn whether the job is silhouette-only or surface.
  5. Choose a global shutter if t_max lands below a few hundred microseconds.
  6. Choose the lighting geometry: broad diffuse for silhouettes, grazing dark field for surface detail; add cross-polarization only if a streak survives.
  7. Strobe the light, fix the exposure, and wire the spindle index to the camera trigger.
  8. Teach the threshold on a known-good part, set the mismatch fraction that flags a change, and log it per part.

The decision, restated once: threshold segmentation is the right real-time method for a turning metal part. Put the engineering into exposure — freeze to the surface speed — and into lighting geometry that separates shape from reflection, not into exotic algorithms, and not into tracking cut progress the CNC already reports. To pick hardware, start in the camera finder and the light finder, or step through the configurator beginning at cameras or lights. Related reading sits on the applications topic page.

Questions

Can I measure the diameter while the part spins?

Yes. Fit sub-pixel edges to both silhouette sides and average over ten or so index-triggered revolutions; averaging cancels the runout wobble of the part in its chuck. At 30 µm per pixel, a rigid bench set-up repeats to a few micrometres; a running lathe with vibration and coolant realistically holds about ±0.05 mm on a Ø40 mm diameter. A telecentric lens removes the perspective error a conventional lens shows when the two edges sit at different distances from the lens.

Do I have to trigger the camera from the spindle?

Only if you want to watch the same spot revolution after revolution — tool wear, a stamped mark, a weld seam. Triggering each exposure from the spindle index pulse lands every frame on the same angular station, and skipped revolutions cost nothing. For silhouette checks such as part presence, swarf wrap or diameter, free-running at 30 fps works fine, because the outline does not move with rotation.

What frame rate do I need at 3000 rpm?

3000 rpm is 50 rev/s, so once-per-revolution sampling needs a camera above 50 fps. A 30 fps camera free-running samples a new angular station roughly every 240°, which suits statistics but cannot track one spot. Either trigger from the index pulse, choose a faster camera, or schedule the inspection on a finishing pass at lower speed — 600 rpm is 10 rev/s, within reach of any current industrial camera.

Why does my threshold flicker between frames?

Usually the illumination, not the algorithm. Mains-driven shop light modulates the scene, auto exposure hunts between frames, and coolant sheen changes the background brightness. Strobe the inspection light so every frame receives an identical pulse, fix or cap the exposure, and if ambient light still leaks in, move the boundary decision to a local-mean adaptive threshold.

Will a rolling-shutter camera work here?

For silhouette segmentation, yes: the outline is static, so readout skew does not touch it. For surface detail at microsecond exposures, no: a flash short enough to freeze 6.3 m/s illuminates only the sensor lines being read at that instant, and a flash long enough to cover the full readout brings the blur back. Below a few hundred microseconds of budget, use a global-shutter sensor.