ApplicationsApplication note

Wood grain classification with machine vision: pixels and color

Machine vision wood grain classification: size the camera by the pixel rule, then lock exposure, white balance and diffuse lighting for repeatable grades.

LumaSpec Vision12 min read Share on LinkedIn

On this page 10 sections
  1. 01Separate the classes before buying hardware
  2. 02Size the camera with the pixel rule
  3. 03Worked example: a 300 mm blank with 2 mm knots
  4. 04What each feature size demands
  5. 05Lighting: diffuse for color, raking for grain
  6. 06Lock exposure, gain and white balance
  7. 07From locked images to grade decisions
  8. 08Pitfalls that flip grades
  9. 09Parts list and next steps
  10. 10Questions

A grader looks at a rifle-stock blank and calls it: clear, character grade, knotty, or reject. A vision system makes the same call on evidence it can re-check years later, identically on every blank and every shift. The engineering reduces to two problems: put enough pixels on the smallest feature your grade rules act on, and hold the image constant so a boundary set on Monday still holds on Friday. Below we size the camera and lens by the pixel rule, choose lighting that keeps grain contrast without sheen, and lock the settings color grading depends on. The worked example sizes a 300 mm rifle-stock blank; the same arithmetic transfers to flooring, panelling, cutting boards or any other wood part.

Separate the classes before buying hardware

Wood grading projects fail on specification, not on camera choice. Write the grade rules down as measurable classes: knots above a size threshold in millimetres, voids and through-holes, surface checks, and color classes such as heartwood against sapwood, mineral streak or stain. Published wood-defect classifiers work the same way, separating knots, cracks and undamaged regions before any grading logic runs.

Grain adds the hard part: the good class is not uniform. Ring spacing, grain density and color vary within a single tree, so the boundary between adjacent grades is a range, not a line. That pushes two requirements onto the imaging: fine sampling so texture features are measurable, and repeatable color so a range measured once stays measured. A camera that cannot hold color re-classifies the same blank across shifts.

Start the software as two classes — known good against known bad — and add grade levels once the boundary holds. The binary image classification for defect detection starting point fits exactly, and the measured-feature approach in grading scratches by severity transfers directly to knots and checks.

Size the camera with the pixel rule

The rule that drives everything downstream: the smallest feature a decision depends on must span at least 3-4 pixels. Below 3 pixels a knot blurs into the grain and no classifier recovers it; at 4 pixels its size measures cleanly with margin.

That fixes the maximum image scale, in millimetres of part per pixel:

image scale (mm/px) = field width / horizontal pixel count pixels needed = field width / (smallest feature / 4)

The defect is not the binding constraint in wood. Latewood bands and grain lines on stock species commonly run a few tenths of a millimetre across, and texture features need several pixels per line before density or direction can be measured. A 0.5 mm grain line at 0.06 mm/px spans about 8 pixels — measurable. At 0.5 mm/px it vanishes.

So compute two numbers: the defect floor sets the minimum camera, and the grain target sets the real one. Pixels per defect: sizing a camera for crack detection works the same logic for cracks, and camera resolution for defect detection runs the sizing rule end to end.

How sensor width, working distance and field of view set the focal length Rays from the edges of the sensor pass through the lens and spread to the edges of the field of view. The ratio of sensor width to field of view is the magnification m.CameraField of view (FOV)Working distance (WD)≈ fsensor width slensm = s / FOVf = WD × m / (1 + m)
How sensor width, working distance and field of view set the focal length. Rays from the edges of the sensor pass through the lens and spread to the edges of the field of view. The ratio of sensor width to field of view is the magnification m.

Worked example: a 300 mm blank with 2 mm knots

Inputs, and where each comes from:

  • Smallest defect to catch: a 2 mm knot — the finest feature that demotes a blank in the grade rules (application input; substitute your own threshold).
  • Blank width 300 mm, plus a 20 mm framing margin for placement scatter — the margin is an allowance; tighten it if your fixture positions precisely.
  • Sampling rule: 4 pixels across the smallest feature (the pixel rule above; 3 pixels is the floor).
  • Camera class: 20 MP color sensor, 1" optical format — 12.8 mm wide, about 5,400 × 3,650 active pixels (typical for this resolution class).
  • Lens: 16 mm focal length, image circle covering 1.1" formats (so it covers the 1" sensor with room to spare).

The rule, in words: frame blank plus margin, divide field width by pixel count to get the image scale, confirm the knot spans 4 pixels, then set the working distance from the field width.

Arithmetic:

  1. Field width: 300 + 20 = 320 mm.
  2. Defect floor: 2 mm ÷ 4 px = 0.5 mm/px allowed, so 320 ÷ 0.5 = 640 pixels minimum. At the 3-pixel floor: 320 ÷ (2 ÷ 3) = 480 pixels. Any industrial camera clears both — the knot is not the constraint.
  3. Grain target: 0.15 mm/px needs 320 ÷ 0.15 ≈ 2,130 pixels; a 20 MP sensor's 5,400 pixels clear it by 2.5×.
  4. Actual scale: 320 ÷ 5,400 = 0.059 mm/px, call it 0.06. Knot: 2 ÷ 0.059 ≈ 34 pixels. A 0.5 mm grain line: ≈ 8 pixels.
  5. Working distance: WD = field × focal ÷ sensor width = 320 × 16 ÷ 12.8 = 400 mm as a first estimate. The exact thin-lens figure: magnification m = 12.8 ÷ 320 = 0.04, WD = f(1 + m) ÷ m = 16 × 1.04 ÷ 0.04 = 416 mm. Plan the stand around 416 mm.
m = sensor width / field width WD = f × (1 + m) / m DOF ≈ 2 × N × c / m²
  1. Depth of field: image-side pixel ≈ 0.059 × 0.04 ≈ 2.4 µm; accept a 5 µm blur circle (2 pixels). At F5.6: DOF ≈ 2 × 5.6 × 0.005 ÷ 0.0016 = 35 mm total, about ±17 mm of height variation across the blank — more than a planed blank ever varies. F5.6-F8 is a sound working aperture; open toward F2.8 only if the light runs short, since exposure is unconstrained on a stationary part.

Result: a 20 MP color camera with a 16 mm lens, working at 416 mm, frames the blank at 0.06 mm/px — 34 pixels on a 2 mm knot and 8 on a typical grain line.

The decision: the knot alone would justify a 640-pixel camera, which is any 1 MP sensor. The grain spec is what forces the purchase: 12 MP meets the 0.15 mm/px texture target with nothing to spare at the frame edges, while 20 MP holds 0.06 mm/px with margin. Buy to the grain, not the knot.

Two parts carry this example. The MV-CS200-10GC is a 20 MP color area scan camera with a 1" sensor, C-mount and GigE interface. The LS-FFL-0567 is a 16 mm, F2.8-22, C-mount lens with <0.3% distortion, rated for 16-25 MP sensors on formats up to 1.1". A 1.1" image circle covers a 1" sensor with room to spare. The camera's rolling shutter costs nothing here because the blank sits still during exposure.

Area scan camerasHikrobot MV-CS200-10GC 20 MP Area Scan Camera, GigE, IMX183, Color, BasicMV-CS200-10GC
Sensor format
1"
Lens mount
C-mount
Interface
GigE
Resolution
16-25 MP
$739.00View partBuild a system with it
Machine vision lenses16 mm, 1.1", 20 MP, C-mount machine vision lens, F2.8-22, <0.3% distortion (LS-FFL-0567)LS-FFL-0567
Type
Machine vision fixed
Sensor format
1.1"
Mount
C-mount
Resolution
16-25 MP
$679.00View partBuild a system with it
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

What each feature size demands

The same 320 mm field, priced feature by feature:

Smallest decision feature Scale needed (4 px) Pixels needed Camera over that field
5 mm knot (rough lumber) 1.25 mm/px 256 any camera, even 1 MP
2 mm knot (stock blanks) 0.5 mm/px 640 any modern camera
0.5 mm grain line measurable 0.125 mm/px 2,560 5 MP and up
0.2 mm hairline check 0.05 mm/px 6,400 25 MP, or the raking pass

The last row explains why precision wood shops keep a second, raking-light shot: at 20 MP (0.06 mm/px) a 0.2 mm check spans 3.4 pixels, which detects but barely measures. Raise the sensor to 25 MP class or bring the raking pass closer, and the check measures too.

Lighting: diffuse for color, raking for grain

Raw machined wood is a friendly surface — mostly diffuse reflection, so a broad soft source gives even illumination and true color. The enemy is sheen: sealed, oiled or finished blanks throw a specular streak that whites out grain contrast exactly where the grader looks. Spread the light rather than pointing it.

A diffused bar light longer than the field, mounted off to the side, is the workhorse for flat and lightly curved blanks. The LS-BAR-1276 is a 372 x 28 mm diffused white bar light that runs on 24 V.

Bar lightsBar light, 372 x 28 mm, White (LS-BAR-1276)LS-BAR-1276
Size
200-400 mm
Type
Diffused
Voltage
24 V
$439.00View partBuild a system with it

At 372 mm it spans the 320 mm field with margin at both ends. Run a pair, one bar each side at roughly 30-45° from vertical, to even out a field this wide; balancing coverage and brightness on a large field walks through that geometry.

For finished or strongly curved parts, a dome light surrounds the blank with diffuse light from every direction — dome lights for shiny, curved and wrinkled parts tells you when the field shape justifies one — and the polarizer technique in lighting shiny metal pins without glare carries over to varnished wood directly.

Grain relief is a different shot. Light raked at a low grazing angle exaggerates ring relief and shallow checks that the diffuse shot flattens. Where cycle time allows, capture both images per blank: diffuse for the color grade, raking for texture. The surface logic in white surface texture inspection: kill the glints applies here unchanged.

Drive the lights from a controller rather than a raw 24 V supply: constant current means constant intensity and color, shot after shot, and keeps mains flicker out of the exposure math. Why your vision light needs a controller gives the full case. Shroud the stage: wood-shop dust settles on diffusers within weeks and quietly dims the field.

Lock exposure, gain and white balance

Color grading lives or dies on repeatability, so fix three things in order:

  1. White balance first. Light the stage, present a neutral gray card, lock white balance to that value and log it. Auto white balance re-decides the color of every frame, and a warmer reading shifts a stain class on its own. The procedure is in locking auto white balance to a fixed value.
  2. Exposure and gain second. Set exposure so the brightest wood in the good class stays below saturation, hold gain at its lowest useful setting, and switch every automatic mode off. One auto-exposure event re-writes your class boundaries invisibly; industrial camera image quality settings covers the trade-offs.
  3. Camera match third. Running two cameras over one line? Verify their color agrees before pooling grades — multi-camera white balance consistency gives the test.

With the chain locked, calibrate the scale once: image a ruler in the plane of the blank and pixels become millimetres, which is what lets the 2 mm knot threshold be enforced in software. The conversion is worked through in calculating pixel distance in real units. Re-shoot the gray card every shift; if the locked exposure needed to hold it moves by more than about 10 percent, clean the diffuser and re-lock before grading.

From locked images to grade decisions

A locked image chain makes simple classifiers strong. A first pipeline that works:

  1. Acquire the diffuse shot — and the raking shot where the cycle allows — under locked settings.
  2. Segment candidates: knots as dark elliptical blobs with ring contrast, voids as sharp-edged holes, checks as thin dark lines the raking image confirms.
  3. Measure in millimetres: knot major axis, check length, void count, plus region statistics — color delta against the class reference, local contrast, gradient direction for grain angle.
  4. Classify: threshold rules on measured features first; a trained binary classifier on those features when thresholds alone cannot hold the line between adjacent grades.

At 0.06 mm/px, the rule that sized the knot also prices cracks: a 0.2 mm hairline spans about 3 pixels — detectable, borderline measurable. Voids read easily because they dwarf the grain features around them. Expect to iterate with your grader: the parts where classifier and human disagree define the boundary better than another hundred clear blanks, so re-label those first.

Pitfalls that flip grades

  • Auto modes left on. Auto exposure and white balance re-grade every blank by the lighting of the moment; this ends more wood-grading projects than any optics error.
  • Sheen on finished blanks. A hard, close light on varnished wood whites out the grain. Fix the lighting geometry before touching software.
  • Ambient drift. Daylight through a shop window walks the histogram across the shift. A shroud and locked light make the cell independent of the room.
  • Motion blur. The example is a stationary shot. If blanks stream past continuously, a rolling shutter sensor needs a short exposure and steady transport, or the station moves to a global shutter camera or line scan.
  • Silent scale drift. Dust on the diffuser, a nudged bracket, a changed aperture — each moves your mm/px. Re-shoot the ruler and gray card at shift start.
  • Color after a lamp change. A replaced bar light with even slightly different output shifts every color class. Re-lock white balance after any hardware change.

Parts list and next steps

The example station: a 20 MP color GigE camera, a 16 mm C-mount lens covering 1.1"-class sensors, a pair of 372 mm diffused white bar lights on 24 V behind a controller, a neutral gray card and a shroud. Browse the area scan cameras category and the machine vision lenses category, start at the camera finder or light finder, and build the system from the camera step.

Before ordering, spend an hour on the bench: set the stand to 416 mm, shoot a ruler for scale, and a dozen blanks spanning your grader's full range. If a 2 mm knot reads about 34 pixels across and grain lines hold 8, the imaging is done and the rest of the project lives in software. If your blanks are wider, finished rather than raw, or graded on the move, re-run the arithmetic above with your own numbers — or send the grade rules through the contact page and we will size the station with you. More inspection builds sit on the applications topic page.

Questions

Does the camera need a global shutter for wood grading?

Only if blanks move during exposure. Grading stations photograph a stationary blank, so the rolling shutter in the example camera costs nothing. If blanks stream past continuously, either shorten the exposure and keep transport steady, or move to a global shutter area camera or a line scan camera driven by an encoder. Freeze the motion first; the pixel rule stays the same either way.

Is mono ever better than color for grain classification?

Yes, when the grade rules are purely textural: a mono sensor reads grain contrast cleanly and skips white-balance discipline. The moment a rule references color — heartwood against sapwood, stain match, mineral streaks — color is required, because that boundary lives in the color channels. Most plants fit color cameras so one image serves both texture and color rules.

How many sample parts are needed to train the classifier?

Start with 30 to 50 parts per class, selected by your grader to span the natural range rather than the easy cases. Re-label every part where classifier and grader disagree; those edge blanks teach more than another hundred obvious ones. Until the boundary holds, threshold rules on measured features carry the line, and the trained classifier switches on afterward.

What lighting angle shows wood grain best?

For color grades and knot detection, a broad diffuse source gives the color-true, glare-free image. A second light aimed nearly along the surface is the one that makes ring relief and shallow checks visible, because it casts a small shadow at every rise. Which shot to keep depends on your grade rules: color rules want the diffuse image, texture rules want the raked one.

How often should lighting and white balance be re-checked?

Once per shift, using the same neutral gray card, and log the locked values. LED intensity drifts slowly with age and temperature, and dust on a diffuser dims the field over weeks. If the locked exposure needed to hold the card's gray level moves by more than about 10 percent, clean the diffuser and re-lock white balance before the next run.

What changes for a wider blank, say 600 mm?

Keep the 0.06-0.15 mm/px texture target: the field grows to about 620 mm with the same margin, so a 20 MP sensor's 5,400 pixels give 620 ÷ 5,400 = 0.11 mm/px — inside the band but near its coarse end. For 0.06 mm/px at that width you need about 10,300 pixels across, which means a 25 MP-class sensor, a narrower field per camera, or two cameras covering the blank end to end.