A reconstruction-based anomaly detector learns what healthy produce looks like. At test time it repaints each image as its nearest healthy version, and wherever the repainted image differs from the real one, it flags a defect. This is attractive for crop inspection because no one has to draw boxes around every bruise, lesion or impurity. Labeling is the step that made grain datasets cost years of expert time and that varies from one inspector to the next. The approach breaks, though, when the camera leaves the lab. A shadow across a leaf or a warmer light on a conveyor is something the healthy model has never seen, so it shows up as a large difference and is flagged as damage.
We propose to give the reconstruction model a second, deliberately narrow channel that carries only the lighting of the input image. The model repaints a lighting-free healthy version of the object, then re-lights it with a smooth lighting field estimated from the input itself. The lighting field is limited to coarse spatial variation, so it can explain broad shading and color casts. It cannot explain a one-percent-of-image lesion or a sharp peel abrasion. The residual should therefore stay near zero for lighting changes and stay large for defects. The design rule is simple: lighting information should be allowed in only at spatial scales below the scale of the defects one cares about. The rule makes a testable prediction. Detection accuracy should trace a U-shaped curve as the lighting field's frequency cutoff is swept, and the curve should be anchored by defect size.
Core Claim
Field failures of reconstruction detectors on agricultural produce mostly come from one source: the model cannot reproduce the input's lighting, so lighting ends up in the residual. Two fixes are available, and neither is ideal. Removing everything that could carry lighting, as abstract edge features do, also removes the subtle color cues that bruises depend on. Letting the reconstruction copy the input freely re-creates the "identical shortcut," where the defect gets reconstructed too and the residual collapses to zero.
A bandwidth-limited lighting path sits between these two extremes. Let $x$ be the input image, $\hat r$ the repainted lighting-free healthy image, and $g$ a per-channel multiplicative lighting field. The pseudo-normal is
$$\hat x = g \odot \hat r, \qquad g(u) = \sum_{k=1}^{K} \ell_k \, \phi_k(u),$$
where $u$ is pixel position, $\phi_k$ are fixed smooth basis functions (low-order 2D cosine terms up to a spatial frequency cutoff $f_c$), and the coefficients $\ell_k$ are predicted from $x$ by a small network. A field band-limited at $f_c$ cannot fit structure much smaller than about $1/f_c$, which follows from basic sampling arguments. As a result, the part of a small defect's residual that $g$ can absorb shrinks as defect size falls below $1/f_c$. Shading from sun angle, color temperature and diffuse canopy light lies mostly below that scale.
Research Program
The model has three parts, and the method contribution is how they are combined.
The first part is the healthy-reconstruction branch. It follows DRÆM, which trains a reconstruction network on normal images with pasted synthetic anomalies (Perlin-noise blends) and adds a discriminative head that reads the input and its reconstruction together to output a defect map. We reuse this recipe to teach the network to erase defects. We change the target: it is $\hat r$, the healthy image before re-lighting, not the input.
The second part is the lighting path. During training it sees normal images re-lit by randomly sampled smooth fields and color casts. The re-lit $\hat x$ must match the re-lit input, while $\hat r$ is shared across lightings of the same image. That sharing is what forces lighting into $g$ and keeps it out of $\hat r$.
The third part handles contaminated training data. Real batches are not clean: Real-IAD shows PaDiM's image-level AUROC (area under the ROC curve) falling from 84.6% to 81.9% at 10% contamination. We therefore adopt the Anomaly Suppression Loss from SwinMAE, which down-weights high-error pixels during training, so the model can learn from unsorted commercial lots.
Prior work plays three different roles here. Two papers motivate the gap. GrainSpace documents hardware-shift collapse and out-of-distribution AUROC below 80% for supervised grain models. PlantSeg documents field collapse for plant-disease segmenters.
Two papers constrain the design. ReDi avoids both the identical shortcut and lighting false positives by reconstructing gradient-histogram (HOG) features. Its own limitation is that HOG misses "missing material" defects. Meanwhile, the apple and potato work (YOLOv12 with filter imaging; Enhanced YOLOv11n) shows that bruises and shallow abrasions live in fine color gradients. Together these rule out abstraction as the route for produce, which is why we keep raw color and model lighting explicitly.
Two papers are the closest neighbors in method. PIAD separates illumination from reflectance and renders a defect-free counterpart, but it needs a per-object 3D Gaussian-splat model and 7.42 seconds per object. That is unusable for thousands of non-rigid kernels per minute, and our method is a single 2D forward pass. FiCo aligns teacher and student features under shift using instance normalization and dynamic convolutions. It has no explicit spatial bandwidth on what may be compensated, and it was tested only on artificially corrupted industrial images and stylized domains.
Baselines
The naive reference point is the same reconstruction network and discriminative head with the lighting path removed, trained on lab normals with standard color jitter. Its gap from the full model measures how much of the field failure the lighting path fixes.
The second baseline is that model preceded by classical color constancy (gray-world white balance plus histogram matching to the lab distribution). This tests whether a global correction is enough.
The strongest existing method under distribution shift is FiCo. It reports an average AUROC of 97.6% on corrupted MVTec AD and 62.3% AUROC on the PACS Sketch domain. We will rerun it with its released configuration on every benchmark below.
For illumination specifically, PIAD reports 92.63% image AUROC and 99.05% pixel AUROC on its real smartphone dataset. We run our 2D model on that dataset to see how much a 3D model is worth, and we compare latency.
Several further baselines cover the remaining design choices. We include SwinMAE as the only agricultural reconstruction detector; it reports 38.0% mIoU on aerial Agriculture-Vision. We include ReDi, which reports 98.8% detection AUROC on MVTec AD, to quantify what HOG abstraction loses on subtle produce defects. We include the diffusion-inpainting detector LMD as a high-cost reference; it averages 0.907 ROC-AUC across its 12 benchmark pairs. We include PaDiM as a frozen-feature reference. As a labeled upper reference we use supervised ConvNeXt-L, which reports 46.24% mIoU on PlantSeg. For unsupervised anomaly detection on PlantSeg, no reported result was found on Lacuna, so all unsupervised numbers there are ours.
Fairness rules apply to every method:
- Each trains on the same normal images at the same resolution.
- Each receives the identical photometric augmentation suite, including the smooth fields used to train our lighting path. Any gain therefore comes from the structured path, not from the augmentation.
- Each gets the same hyperparameter-search budget in GPU-hours.
- Decision thresholds are chosen on lab validation data only.
The key ablation sweeps $f_c$ from a global gain only, through several intermediate cutoffs, up to an unconstrained full-resolution field. We expect the full-resolution end to show the identical shortcut. We count the method as successful if it beats FiCo on field-shifted pixel AUROC by more than seed-to-seed variation and its performance stays flat across lighting strata.
Why not just…?
Why not just white-balance the images first? Global color correction fixes color temperature. It cannot remove a shading gradient across a curved apple or a soft canopy shadow, and those spatially varying effects are what we expect to dominate field residuals. The color-constancy baseline and the "global gain only" point of the $f_c$ sweep test this directly. If they match the full model on field data, then spatial structure is not the issue and we would report that.
Why not just train any detector with heavy lighting augmentation? This is the most serious alternative. A reconstructor trained to reproduce augmented inputs may simply learn to reproduce lighting, and a high-capacity one may learn to reproduce defects as well. Real-IAD and the identical-shortcut analyses in ReDi suggest that more capacity to copy the input is exactly what hurts. Because every baseline receives the same augmentation, the comparison settles the question. If augmented baselines close the gap, the band-limited path is unnecessary and the contribution shrinks to a negative result.
Why not just use feature-space normalization like FiCo, or frozen pretrained features? These methods normalize away style without a spatial limit on what counts as style. On produce, where normal appearance itself varies in color, that risks normalizing away bruises. We test FiCo directly on the same splits and report results by defect size. Our prediction is that FiCo's deficit concentrates on small, low-contrast defects.
Why not just train a supervised detector? On known classes, supervised detectors are strong; Enhanced YOLOv11n reports 97.0% [email protected] on potato peel damage. However, GrainSpace reports 71.6% AUROC for supervised models flagging deleterious out-of-distribution grain. Labels for supervised training are also the costly, inspector-dependent step we aim to remove. We use supervised models only as labeled upper references.
Proposed Experiments
We test lab-to-field transfer in three regimes.
- Leaves. We train on the healthy-leaf images in PlantVillage, which are lab-captured on uniform backgrounds. We test on PlantSeg field images using pixel AUROC and thresholded mIoU, scored within leaf regions from a class-agnostic segmenter, with a hand-checked subset to bound segmentation error. KUTomaDATA's healthy and diseased greenhouse leaves give a second field test.
- Grain hardware shift. We train on sound kernels from GrainSpace's industrial P600/G600 hardware and test defect and impurity detection on M600 mobile captures. The 71.6% figure comes from a supervised protocol, so we will state clearly where our protocol differs from it.
- Controlled stress tests. We run corrupted MVTec AD, the PIAD dataset, and Real-IAD with contamination ratios from 0 to 0.2.
The decisive checks are three predictions. First, field accuracy as a function of $f_c$ should rise and then fall. The peak should move to lower cutoffs when evaluation is restricted to smaller lesions, and PlantSeg's small, low-convexity lesions give a natural size stratification. If the curve is flat, or the peak does not track defect size, the mechanism is wrong.
Second, the residual energy that the lighting path absorbs should be large on lighting-only perturbations of normal images and near zero on synthetic defects of known size.
Third, hard cast shadows with sharp edges should remain a residual failure mode. We will measure it separately rather than hide it.
Finally, as an analysis that bears on subjective grading, we test whether the continuous anomaly score is ordinally consistent with the four market grades in the DXNet apple dataset, measured by Spearman correlation. We also report throughput on edge hardware against PIAD's per-object cost.
References
- DRÆM - A discriminatively trained reconstruction embedding for surface anomaly detection
- Real-IAD: A Real-World Multi-View Dataset for Benchmarking Versatile Industrial Anomaly Detection
- Label-free Anomaly Detection in Aerial Agricultural Images with Masked Image Modeling
- GrainSpace: A Large-scale Dataset for Fine-grained and Domain-adaptive Recognition of Cereal Grains
- A Large-Scale In-the-wild Dataset for Plant Disease Segmentation
- A recover-then-discriminate framework for robust anomaly detection
- Enhanced Research on YOLOv12 Detection of Apple Defects by Integrating Filter Imaging and Color Space Reconstruction
- Enhanced <scp>YOLOv11n</scp> : A Method for Potato Peel Damage Detection
- PIAD: Pose and Illumination agnostic Anomaly Detection
- Filter or Compensate: Towards Invariant Representation from Distribution Shift for Anomaly Detection
- Unsupervised Out-of-Distribution Detection with Diffusion Inpainting
- Research on Apple External Quality Grading Method Based on DXNet Model