Cameras & sensorsHow-to

RGB-IR camera per-channel gain: compensate IR in software

RGB-IR cameras give you one analog gain, not four. Measure the IR leak, apply per-channel digital gains or a 3×3 matrix, and wire the hardware trigger.

LumaSpec Vision11 min read Share on LinkedIn

On this page 10 sections
  1. 01Why there is only one analog gain
  2. 02What the IR leak does to each channel
  3. 03Step 1: measure the leak and set the per-channel digital gains
  4. 04Keep the bit depth and channel order honest
  5. 05Step 2: fit a 3×3 matrix when color matters
  6. 06When gains cannot get there: split the passes
  7. 07Step 3: wire and enable the hardware trigger
  8. 08Prove the trigger works: tests and failure signatures
  9. 09Which route fits your station
  10. 10Questions

Your RGB-IR board camera sees visible color and NIR with one sensor, and the first control you went looking for — a separate analog gain per channel — is not on the camera. This guide gives you the working substitute and the trigger set-up. You will set one analog gain that protects the red channel from clipping, measure the IR leak on a gray card and correct it with per-channel digital gains, then wire and enable the hardware trigger so every pulse buys exactly one frame.

Why there is only one analog gain

In a CMOS sensor the color split happens optically, at the filter array on top of the silicon: red, green, blue and clear IR sites sit side by side. Underneath, every pixel drains through the same readout chain — one analog gain stage, then the ADC. That single gain register is what the camera's gain control moves, and it multiplies every pixel by the same factor. A separate analog gain for red would need extra gain paths switched pixel group by pixel group, and stock parts do not carry them; this is a factory-customization question, not a setting you have overlooked.

So everything you control per channel happens after the ADC, and the order is worth keeping in mind because it decides what each control does. Analog gain lifts signal before quantization and buys real signal-to-noise improvement. Digital gain after the ADC rescales numbers and their noise together. The pipeline article walks that chain stage by stage: Camera pipeline order: analog gain, ADC, then digital gamma.

The strategy for the rest of this guide follows from that split: analog gain for headroom on the loudest channel, digital gains for balance on the others.

What the IR leak does to each channel

An RGB-IR sensor removes the IR-cut filter and hands NIR its own clear sites in the filter array, usually carved out of green. Silicon keeps responding well past 700 nm, so the red, green and blue sites collect NIR on top of visible light. The red filter passes the longest wavelengths, closest to the NIR band, so red collects the most contamination, green next, blue the least. The light source sets the amounts: a halogen lamp or an IR LED bank floods all three channels, while a narrowband visible LED array barely moves them. That illumination sensitivity is also why the sensor's auto white balance never looks right across scenes.

The standard cure, an IR-cut filter, is off the table here: it would starve the clear IR sites, which are the point of the design. On a conventional camera that same missing filter is its own failure mode: When black objects look white in your images: missing IR-cut filter.

Step 1: measure the leak and set the per-channel digital gains

  1. Lock the camera down: fixed exposure, analog gain at its lowest step, auto exposure and auto white balance off. Any auto mode will fight your correction while you measure. The runtime parameter control article shows how to drive exposure and balance live while you test.
  2. Capture raw if you can. ISP-corrected 8-bit RGB has already had white balance applied by someone else's algorithm; do the math upstream of that. Bayer raw stream from an RGB camera: how to know you have it shows the check.
  3. Light a matte gray or white reference card with the production illumination and shoot it, with the card filling at least a 200 × 200 pixel patch near the image center.
  4. Average each channel inside that patch: Rmean, Gmean, Bmean.
  5. Anchor green and compute the two gains: gR = Gmean / Rmean and gB = Gmean / Bmean.
  6. Apply the gains before any gamma or color conversion, then re-shoot the card. The three channel means should agree within ±2% when you are done.
gR = Gmean / Rmean gB = Gmean / Bmean clip check: peak_ch * g_ch <= 2^bits - 1

Now the clip check from the formula block. Say the brightest blue-site pixel in a full test frame reads 2600 DN: 2600 × 1.474 = 3832 DN, inside the 4095 DN ceiling of a 12-bit word. If it read 2900 DN instead, 2900 × 1.474 = 4275 DN and the top of that pixel's range clips. The fix is exposure, not gain: trimming exposure from 4 ms to 3 ms scales every channel by 0.75, so the blue peak lands at 1950 DN and 1950 × 1.474 = 2874 DN, back inside range. The ratios gR and gB do not move with exposure — all channels scale together — so the calibration survives the trim.

One cost to watch: the ×1.474 blue gain also multiplies blue noise by 1.474, so a 2 DN read-noise floor becomes about 3 DN. When a channel needs more than roughly ×2 digital gain, more light or a longer exposure beats more gain.

Keep the bit depth and channel order honest

Two mistakes undo an otherwise correct calibration.

Bit depth first. Many USB raw streams carry 10- or 12-bit data left-aligned in a 16-bit container, so full scale is not 65535; 12-bit data tops out near 65520 (4095 × 16). A gain computed against 16-bit full scale under-corrects and leaves a color residue you can chase for hours. 12-bit data in a 16-bit V4L2 frame: why values top out near 65520 shows the signature. Confirm the true bit depth once, before you scale anything.

Channel order second. If red and blue are swapped in your buffer, the "red correction" lands on blue and doubles the error. Put a red card and a blue card in one frame and check which channel peaks: Red and blue channels swapped: why RGB images look wrong walks the test. Do it once at set-up.

Step 2: fit a 3×3 matrix when color matters

Three scalars make neutrals neutral; they do not make colors correct, because IR contamination adds across channels and the filter array bleeds between neighboring sites. When the application judges color rather than just brightness, fit a 3 × 3 correction matrix that maps measured RGB to reference RGB, shooting a patch set of known colors under the production illumination, and apply it after the per-channel gains. Refit whenever the illumination changes — a different lamp, a new IR LED bank, a lens swap all move the coefficients.

For defect detection on shape and presence, the scalars are enough most of the time; judge that on a reject sample before spending an afternoon on color patches. Whatever you choose, keep a gray patch in the corner of the field of view and flag its three means when they drift more than 5% from calibration: that is the tell that the illuminant moved and the gains went stale. The numeric check to automate is in Programmatic camera white balance control: verify settings.

If you also specify the lighting, this is the cheapest lever of all: narrowband visible LEDs with little emission past 700 nm shrink the leak at the source, and every coefficient downstream gets smaller with it.

When gains cannot get there: split the passes

Software correction works on the photons that arrived; it cannot separate light the sensor mixed at the surface. When the visible pass needs clean color and the NIR pass needs contrast, separate them optically.

For a static part, shoot two passes: one frame through an IR-cut filter for color, one through an IR bandpass around 850 nm for NIR. Where that filter lives — in the lens or as a coating on the sensor board — changes how you add or remove it: M12 lens IR cut filter: is it in the glass or on the board. Both frames can come from one trigger pulse: Multi image capture per trigger: get an image set from one shot covers the pattern.

For moving parts, use two cameras — one color behind an IR-cut filter, one mono behind the IR bandpass — triggered together. Two standard board-level cameras do this with no correction matrix at all:

Board-level camerasUSB3.0 board camera / module, 1.3 MP, Color (LS-BCM-0047)LS-BCM-0047
Sensor format
1/2.7"
Lens mount
C-mount
$179.00View part
Board-level camerasHikrobot MV-CB016-10GM-M-W 1.6 MP GigE board-level camera, IMX296, Mono, M12 lens mount, WTB GigE portMV-CB016-10GM-M-W
Sensor format
1/2.9"
Lens mount
M12
$559.00View part

The LS-BCM-0047 carries the visible pass: 1.3 MP color, 1/2.7" sensor, global shutter, C-mount, USB3. The MV-CB016-10GM-M-W takes the NIR pass: 1.6 MP mono, 1/2.9" sensor, global shutter, M12 mount, GigE link. Choosing among the rest of the catalog for these two slots is the same exercise as any embedded build: Board level camera selection for embedded vision machines.

Step 3: wire and enable the hardware trigger

  1. Identify the trigger input and its ground reference from the maker's external-trigger application note — on board cameras it is usually a pad or pin header on the PCB edge, labeled on the silk.
  2. Confirm the logic level before wiring anything. Power the board and measure the pad's pull-up rail: sensor GPIO banks commonly run at 3.3 V or below, and a 5 V source into a 3.3 V input — or a 24 V PLC output into either — kills the input stage. Drive a 24 V source through an optocoupler or a divider down to the pad's level.
  3. Keep the wire short: under about 15 cm of fly-wire, a 100–330 Ω series resistor from the source, and the source ground tied to the camera ground.
  4. Set the pulse width from the note's minimum. If the note is silent, start at 1 ms, shorten it until frames go missing, then back off by a factor of ten — that is your working width with margin.
  5. Run the vendor's enable sequence once, in order, after every power-up or USB re-enumeration: the note's control-menu settings plus its step file. The sequence arms the trigger; a step run out of order, or before the camera has enumerated, leaves the sensor free-running.
  6. Point your capture code at the armed trigger. If you drive the camera through the vendor's own driver, the trigger settings surface as that driver's properties — the properties expose the function, the enable sequence still arms it. On Linux over UVC the same settings appear as V4L2 controls: UVC camera external trigger on Linux: enable it with V4L2 controls.

Before you commit to any camera's trigger input on a new design, USB camera external trigger support: how to decide lists the points to settle from the data sheet.

Prove the trigger works: tests and failure signatures

Fire 1000 pulses at 10 Hz and count captured frames. 1000 frames closes the task. The signatures worth knowing:

  • Frames arrive, but the camera also streams between pulses: the enable sequence did not run, or ran out of order.
  • Roughly 500 frames from 1000 pulses: one frame per two pulses — pulse width or trigger edge. Check the width from step 4 and the note's rising/falling edge selection.
  • Capture times out after the first frame: the stream or buffer side, not the trigger. Camera buffer timeout on external trigger: fix the source first sorts the source from the symptom.
  • One-shot software triggering hangs during bench testing: Camera trigger ready timeout: diagnose software triggering is the diagnostic path.

Measure latency once, too. Gate a flash LED from the same trigger pulse, set exposure longer than the flash duration, and check that every frame catches the flash — the flash, not the exposure, is what freezes motion. You now have the pulse-to-exposure delay for your timing budget.

Which route fits your station

Per-frame color and NIR from one camera, illumination fixed: analog gain set for red headroom, digital gains from the gray card at ±2% neutral tolerance, a 5% drift alarm on the in-corner gray patch. Color-critical work: add the 3 × 3 matrix and refit on any illumination change. Static part: two filtered passes from one pulse. Moving parts: two cameras on one trigger. In every case the trigger discipline is the same — logic level measured at the pad, enable sequence once per session, and 1000 pulses in, 1000 frames out.

Still choosing hardware? The camera finder filters the area scan cameras and board-level cameras lines, and the configurator below walks the selection. If a station needs a review before you order, the applications team contact page is the way in.

Build the whole station

The configurator matches a camera, lens, light, light controller and cables to each other, step by step, and lists only parts that fit what you already picked.

Start with the camera

Questions

Can I add an IR-cut filter to an RGB-IR camera to clean up the color?

Not if the NIR channel still matters: an IR-cut filter blocks the near-infrared that the clear IR sites exist to collect, so it disables the RGB-IR design's second channel. Correct the leak in software per channel instead, or split optically — one pass behind an IR-cut filter for color, one behind an 850 nm bandpass for NIR, both from a single trigger.

Which channel does IR contaminate most on an RGB-IR sensor?

Red, then green, then blue. The red filter passes the longest wavelengths, nearest the NIR band, so it collects the most out-of-band light; blue sits furthest away. The magnitudes track your illumination's NIR content, so measure under the production lights rather than copying gains from another station — a halogen lamp and a narrowband LED give very different numbers.

Does per-channel digital gain cost image quality compared with analog gain?

Yes. Analog gain amplifies signal before the ADC, improving signal against quantization noise. Digital gain multiplies converted numbers, scaling noise and signal together — a ×1.5 blue gain also multiplies blue noise by 1.5. Keep digital gains moderate; once a channel needs more than about ×2, add light or exposure rather than gain.

Do I have to rerun the trigger enable sequence after a USB replug or power cycle?

Yes. Treat the armed state as volatile: it does not survive power loss or re-enumeration, and the sensor returns to free-running. Run the vendor's sequence, in order, once per session after the camera enumerates. Driver-side trigger properties can be set at any point afterward — they expose the armed function, they do not replace the enable step.

What trigger pulse should I send the camera?

A clean single-edge pulse at the logic level the application note gives for the trigger input — measure the pad's pull-up rail to confirm it; sensor GPIO banks commonly sit at 3.3 V or below. Match the note's edge selection (rising or falling), respect its minimum pulse width, and keep the repetition rate below the camera's maximum frame rate so pulses never outrun readout.