Decades behind the camera usually means decades of RAW originals with retouched finals sitting beside them. That archive is more than a portfolio: an original plus its retouched version is a supervised training pair, and a few thousand aligned pairs are enough to fine-tune a model that takes over the repetitive half of the cleanup — leaf blemishes, insect damage, distraction removal. The catch is alignment and scale, and both have numbers. What follows gives the registration tolerance that separates useful pairs from wasted ones, the mask rules that turn a difference into labels, the pair counts each training approach needs, and the capture station that keeps new material trainable.
What a before and after archive gives you
Treat the RAW original as the input x and the retouched export as the target y. A model trained on that mapping learns your retouching decisions rather than a generic idea of clean foliage. The structure is proven rather than speculative: recent retouching-transfer research trains on exactly this kind of paired data, and published portrait-retouching collections run to about 30,000 before and after pairs.
Split the edits into two families before anything else, because they train differently:
- Local pixel edits — leaf blemishes, insect damage, petal specks, removed distractions. The model changes a small region and leaves the rest of the frame untouched. This is detection plus inpainting, and it is where the repetitive hours go.
- Global edits — tone curves, color grades, selective focus, attention control. These move the whole frame consistently. They belong to a separate tone-mapping stage, or they stay manual.
Train the local model first: clearest ground truth, easiest evaluation, biggest saving. Judging what counts as a blemish on natural material is itself the hard problem in AI defect inspection for products with natural appearance variability; your pairs encode that judgment, which is exactly their value.
Register the pairs before anything else
A retouched export is rarely pixel-true to its original. Crops, straightening, resizes and perspective corrections all shift the geometry, and a model trained on misaligned pairs learns to blur, because the target's leaves sit a few pixels off the input's leaves. Register every pair with the original as reference:
- Convert each RAW with one fixed recipe — same demosaic, same working color space, 8-bit — and bring the retouched TIFF into that same space. A color-space mismatch reads as an edit everywhere.
- Match each final to its exact original before spending compute on it: correlate downscaled thumbnails and confirm the pairing. Decades of near-identical variants are the biggest silent error in an archive like this.
- Estimate the geometric transform from final to original — feature matching for a starting homography, refined by intensity-based alignment — resample the final into the original's geometry, and log the residual.
Decision rule: keep pairs whose root-mean-square residual lands under 1 pixel. Between 1 and 2 pixels a pair still serves coarse distraction removal; above 2 pixels, discard it. Keep pairs whose final overlaps at least 90% of the original frame. Expect to cull 10-30% of the archive to aggressive crops and mismatched variants, and count the dataset after the cull, not before.
Making pixel coordinates correspond between images is the same discipline as locating image defects with pixel coordinates and calibration — the transform is the product.
Turn the difference into edit masks
Once the pairs are aligned, the edit is simply the difference. Take the absolute per-channel difference between original and final, then:
- Subtract each channel's median difference first, so a global grade does not label the whole frame as edited.
- Threshold what remains at about 12 of 255 levels.
- Drop connected components under about 50 pixels — conversion noise and sensor dust, not retouching.
- Dilate the survivors by roughly 16 pixels, so each mask carries the blemish's edge, not just its center.
Audit about 5% of the masks by eye, or 50 of them when 5% is fewer. These masks are free labels for two models at once: a detector trained on the originals to predict where you would retouch, and the fine-tuning target for the model that performs the retouch. Color handling that differs between your originals and the training inputs is a classic silent failure — color normalization training pipeline: verify model inputs covers the checks.
How many pairs you need
Count aligned pairs after the cull, then place yourself:
| Aligned pairs | What works | What to expect |
|---|---|---|
| Under 300 | General inpainting model with hand-drawn or detector masks; train only the detector | The model will not learn your style; it saves marking time at best |
| 300-1,000 | Low-rank (LoRA) adapter on an open inpainting model, rank 16 as a sensible default | Your style appears; review every output |
| 2,000-5,000 | Full fine-tune of the inpainting stage | The first pass beats manual work on blemish and distraction classes |
| 10,000 and up | Add the global look model on top | The scale published paired retouching datasets reach |
Published inpainting fine-tunes typically train on 512 × 512 pixel crops, so cut tiles around the masks — about four masked tiles for every clean tile, so the model also learns to leave healthy foliage alone. Hold out 10% of capture sessions, never a random 10% of tiles: the same plant photographed twice leaks across a random split. Accept the fine-tune when structural similarity inside the masks on the held-out sessions clears roughly 0.90; blemish removal is reproduction, not generation, so a high bar is correct.
Storage is modest. A 512 × 512 tile as 8-bit RGB is about 0.79 MB, the mask another 0.26 MB, so an input-target-mask set is about 1.8 MB per pair — 5,000 pairs is roughly 9 GB. Training itself is GPU work, and the reason is memory bandwidth: why GPUs beat CPUs for deep learning training lays it out. When the first run misbehaves, mask and folder errors are the usual suspects — anomaly detection custom dataset training: fix folder and mask errors names the common ones.
The pipeline to build first
Build in this order:
- Detector. A segmentation model on the originals that predicts your retouch masks. It trains on a few hundred annotated frames, and the difference masks are its annotations for free.
- Inpainter. An open latent-diffusion inpainting model, fine-tuned on the pairs, filling masked regions from the surrounding foliage.
- Look. The global grade, fit from the unmasked difference as a tone mapping — a 3D LUT or a small pixel-to-pixel network.
- Review. You keep the last pass, on the frames the model flags as edited.
At inference the frame runs original, then detector, then inpaint, then look, then your desk. Instruction-following editing models work without pairs at all, but they do not reproduce your decisions; with pairs in hand, paired fine-tuning wins on consistency. Where instruction-driven models fit an inspection line at all is a separate question — vision language models for inspection: where they fit. And if the detector later moves to the line, flagging blemished stock at grading, that job belongs to smart cameras; the learned-versus-rule-based choice there is covered in AI vs rule-based smart camera inspection: how to choose.
A capture station for new pairs
Quality is decided at capture. A fixed station — same camera, same lens, same light, locked exposure and white balance — means every new original lands in the distribution the model trained on, and the only thing that varies is the plant. Lock the exposure before the first frame rather than letting it drift between sessions; the ordering discipline is the one described for streaming set-ups in set manual exposure before streaming: initialization order. Adding the model to hardware you already own follows the pattern in adding AI surface defect inspection to existing cameras.
Pick an area scan camera around 20 MP with C-mount. The MV-CS200-10GC is a GigE option; the MV-CS200-10UM is its USB3 sibling. For one station, USB3 keeps the wiring simple; for several stations or long cable runs, GigE.
| Specification | MV-CS200-10GC | MV-CS200-10UM |
|---|---|---|
| Max. frame rate | 5.9 fps @ 5472 × 3648 | 19.2 fps @ 5472 × 3648 Mono 8 |
| Exposure time | 46 μs to 2.5 sec | 44 μs to 0.83 sec |
| Exposure mode | Off/Once/Continuous exposure auto, supports Timed and Trigger Width exposure mode, and Rolling and Global Reset sensor shutter mode | Off/Once/Continuous exposure mode, supports Global Reset and Rolling |
| Pixel format | Mono 8/10/12, Bayer GB 8/10/10p/12/12p, YUV422Packed, YUV422_YUYV_Packed, RGB 8, BGR 8 | Mono 8/10/10Packed/12/12Packed |
| Decimation | Supports 1 × 1, 2 × 2 | Supports 1 × 1, 2 × 2, 4 × 4 |
| Reverse image | Supports horizontal and vertical reverse image output | Supports horizontal and vertical reverse image output |
| Data interface | Gigabit Ethernet, compatible with Fast Ethernet | USB3.0, compatible with USB2.0 |
| Digital I/O | 6-pin Hirose connector provides power and I/O, including opto-isolated input × 1 (Line 0), opto-isolated output × 1 (Line 1), bi-directional non-isolated I/O × 1 (Line 2). | 6-pin P7 connector provides power and I/O, including opto-isolated input × 1 (Line 0), opto-isolated output × 1(Line 1), bi-directional non-isolated I/O × 1 (Line 2) |
| Power supply | 9 VDC to 24 VDC, supports PoE | 9 VDC to 24 VDC, supports USB3.0 power supply |
| Power consumption | Typ. 2.5 W @ 12 VDC | Typ. 2.3 W @ 5 VDC (USB3.0 provides power supply) |
| Dimension | 29 mm × 29 mm × 42 mm (1.1" × 1.1" × 1.2") | 29 mm × 29 mm × 30 mm (1.1" × 1.1" × 1.2") |
| Weight | Approx. 100 g (0.22 lb.) | Approx. 80 g (0.18 lb.) |
| Price | $739.00 | $759.00 |
All 2 share: Sensor type CMOS, rolling shutter; Sensor model Sony® IMX183; Pixel size 2.4 μm × 2.4 μm; Sensor size 1"; Resolution 5472 × 3648; SNR 41.5 dB; Gain 0 dB to 24 dB; Binning Supports 1 × 1, 2 × 2, 4 × 4. Values as printed in each product's data sheet; open a part for its drawing and full specifications.
Worked example — sizing the station around a 300 mm wide flat of plants. A Type 1" sensor is about 13 mm wide, so:
A 16 mm lens therefore frames the flat at roughly 385 mm working distance. One pixel covers about 0.055 mm on the plant, so a 2 mm leaf blemish spans 36 pixels — comfortable for detection and for an inpainting mask — while a 0.5 mm speck spans 9 pixels; below about 1 mm of defect size, this field of view stops training anything. The geometry and the pixel arithmetic are the subjects of blister inspection working distance and field of view and calculating object space pixel size from magnification.
Depth of field at f/8 with the circle of confusion set to one pixel (about 2.4 µm) is 2 × 8 × 0.0024 mm × 1.0433 / 0.0433² ≈ 21 mm total, roughly ±10 mm about the focus plane — enough for a flat subject with some leaf relief.
For the lens, the LS-FFL-0567 is a 16 mm C-mount type rated for 1.1" sensors at 20 MP-class resolution, with an F2.8-22 iris and distortion under 0.3%.
- Type
- Machine vision fixed
- Sensor format
- 1.1"
- Mount
- C-mount
- Resolution
- 16-25 MP
Light the station with fixed, diffused panels and never re-aim them between sessions. With strobes, frame on the modelling light and keep your eyes out of the direct flash at full power. Shoot RAW always — the pairs need the unprocessed original. Parts to browse are in the machine vision lenses range and the camera finder and lens finder.
When the usual answer is wrong
- Selective focus and attention control do not pair-train. They are semantic edits: the model must decide what matters, and a paired translator will invent texture where it should not. Keep them manual, or feed only their tone component to the look model.
- Style drift breaks one-model-fits-all. Decades of archives usually contain several retouching hands. A single model trained across them returns the average — soft, cautious edits. Bucket by era or retoucher and train the largest bucket.
- Dust is not a retouching decision. Clean the sensor, or map the dust once and subtract it; do not spend dataset capacity learning it.
- Wholesale replacements are a different task. New skies and composited backgrounds produce masks covering half the frame; pull those pairs out.
Checks before the first training run
- Every final matched to its exact RAW variant — mismatched pairs poison both models silently.
- One RAW recipe and one working color space across the whole set — pipeline drift reads as edits.
- Registration residuals logged; pairs over 2 px root-mean-square or under 90% overlap removed.
- 5% of masks audited by eye, 50 minimum.
- Split by capture session, with 10% of sessions held out.
- A baseline run with the un-fine-tuned model recorded, so the fine-tune gain is measured against something.
Start with the archive you already own: register, mask, count. When you add the capture station, the camera step of the system configurator walks camera, lens and light together. More camera-side work is indexed under the cameras topic, and pipeline questions can go through the contact page.
Questions
Do the retouched finals need to stay in 16-bit for training?
No. Convert originals and finals into one 8-bit working color space for the difference step and the training crops, and keep the 16-bit masters untouched for future reprocessing. The masks and the detector gain nothing from the extra depth, and 16-bit triples storage and load time for no measurable benefit. Re-derive the masks whenever you change the RAW recipe, because they are defined relative to it.
How do I judge alignment by eye before batch-checking residuals?
Overlay the registered pair in difference mode at full zoom on leaf veins and petal edges. One crisp edge line means the pair is aligned; a doubled line one to two pixels wide is borderline; a visible ghost means the transform is wrong. Check the center and two corners, because homography error grows away from the match points.
Can one model learn every retoucher's style in the archive?
Not as a single training set. Different hands apply different heal sizes, sharpening and color decisions to the same blemish, and a model trained across all of them returns the average: soft, cautious edits that fix nothing decisively. Sort the pairs by retoucher or era, train on the largest coherent bucket, then adapt to the other styles with separate low-rank adapters, which are small enough to keep one per style and swap at inference.
Will the model also absorb my exposure and color corrections?
Only if you let them leak. Subtract each channel's median difference before thresholding, so a global grade cannot label the whole frame as an edit; that keeps the inpainter focused on local retouching. To reproduce the grade itself, fit it from the unmasked difference as a separate tone mapping and apply it after inpainting. The split also lets you change your grade later without retraining the retouching model.
How much compute does the fine-tune need?
For 300 to 1,000 pairs, a low-rank adapter at 512 × 512 crops trains on a single 24 GB GPU in hours rather than days. The full fine-tune above roughly 2,000 pairs needs gradient checkpointing or smaller batches on the same card. The detector stays light on compute throughout; a few hundred frames train it there too. The stage you will actually feel is registration, which is CPU time across the entire archive.
