- Introduction: Why grayscale photographs may have an effect on anomaly detection.
- Anomaly detection, grayscale photographs: Fast recap on the 2 predominant topics mentioned on this article.
- Experiment setting: What and the way we examine.
- Efficiency outcomes: How grayscale photographs have an effect on mannequin efficiency.
- Velocity outcomes: How grayscale photographs have an effect on inference velocity.
- Conclusion
1. Introduction
On this article, we’ll discover how grayscale photographs have an effect on the efficiency of anomaly detection fashions and look at how this selection influences inference velocity.
In laptop imaginative and prescient, it’s nicely established that fine-tuning pre-trained classification fashions on grayscale photographs can result in degraded efficiency. However what about anomaly detection fashions? These fashions don’t require fine-tuning, however they use pre-trained classification fashions comparable to WideResNet or EfficientNet as characteristic extractors. This raises an vital query: do these characteristic extractors produce much less related options when utilized to a grayscale picture?

This query is not only educational, however one with real-world implications for anybody engaged on automating industrial visible inspection in manufacturing. For instance, you may end up questioning if a colour digital camera is critical or if a less expensive grayscale one might be adequate. Or you can have considerations concerning the inference velocity and wish to use any alternative to extend it.
2. Anomaly detection, grayscale photographs
If you’re already aware of each anomaly detection in laptop imaginative and prescient and the fundamentals of digital picture illustration, be happy to skip this part. In any other case, it gives a short overview and hyperlinks for additional exploration.
Anomaly detection
In laptop imaginative and prescient, anomaly detection is a fast-evolving subject inside deep studying that focuses on figuring out uncommon patterns in photographs. Sometimes, these fashions are educated utilizing solely photographs with out defects, permitting the mannequin to be taught what “regular” seems like. Throughout inference, the mannequin can detect photographs that deviate from this realized illustration as irregular. Such anomalies usually correspond to numerous defects that will seem in a manufacturing surroundings however weren’t seen throughout coaching. For a extra detailed introduction, see this hyperlink.
Grayscale photographs
For people, colour and grayscale photographs look fairly comparable (except for the shortage of colour). However for computer systems, a picture is an array of numbers, so it turns into a little bit bit extra sophisticated. A grayscale picture is a two-dimensional array of numbers, usually starting from 0 to 255, the place every worth represents the depth of a pixel, with 0 being black and 255 being white.
In distinction, colour photographs are usually composed of three such separate grayscale photographs (referred to as channels) stacked collectively to type a three-dimensional array. Every channel (pink, inexperienced, and blue) describes the depth of the respective colour, and its mixture creates a colour picture. You may be taught extra about this right here.
3. Experiment setting
Fashions
We are going to use 4 state-of-the-art anomaly detection fashions: PatchCore, Reverse Distillation, FastFlow, and GLASS. These fashions characterize various kinds of anomaly detection algorithms and, on the similar time, they’re broadly utilized in sensible functions because of quick coaching and inference velocity. The primary three fashions use the implementation from the Anomalib library, for GLASS we make use of the official implementation.

Dataset
For our experiments, we use the VisA dataset with 12 classes of objects, which gives a wide range of photographs and has no color-dependent defects.

Metrics
We are going to use image-level AUROC to see if the entire picture was categorised accurately with out the necessity to choose a specific threshold, and pixel-level AUPRO, which exhibits how good we’re at localizing faulty areas within the picture. Velocity might be evaluated utilizing the frames-per-second (FPS) metric. For all metrics, increased values correspond to higher outcomes.
Grayscale conversion
To make a picture grayscale, we are going to use torchvision transforms.

For one channel, we additionally modify characteristic extractors utilizing the in_chans parameter within the timm library.

The code for adapting Anomalib to make use of one channel is on the market right here.
4. Efficiency outcomes
RGB
These are common photographs with pink, blue, and inexperienced channels.

Grayscale, three channels
Pictures had been transformed to grayscale utilizing torchvision remodel Grayscale with three channels.

Grayscale, one channel
Pictures had been transformed to grayscale utilizing the identical torchvision remodel Grayscale with one channel.

Comparability
We will see that PatchCore and Reverse Distillation have shut outcomes throughout all three experiments for each picture and pixel-level metrics. FastFlow turns into considerably worse, and GLASS turns into noticeably worse. Outcomes are averaged throughout the 12 classes of objects within the VisA dataset.
What about outcomes per class of objects? Perhaps a few of them carry out worse than others, and a few higher, inflicting the typical outcomes to look the identical? Right here is the visualization of outcomes for PatchCore throughout all three experiments displaying that outcomes are fairly secure inside classes as nicely.

The identical visualization for GLASS exhibits that some classes will be barely higher whereas some will be strongly worse. Nevertheless, this isn’t essentially brought on by grayscale transformation solely; a few of it may be common consequence fluctuations because of how the mannequin is educated. Averaged outcomes present a transparent tendency that for this mannequin, RGB photographs produce the perfect consequence, grayscale with three channels considerably worse, and grayscale with one channel the worst consequence.

Bonus
How do outcomes change per class? It’s doable that some classes are merely higher suited to RGB or grayscale photographs, even when there aren’t any color-dependent defects.
Right here is the visualization of the distinction between RGB and grayscale with one channel for all of the fashions. We will see that solely pipe_fryum class turns into barely (or strongly) worse for each mannequin. The remainder of the classes change into worse or higher, relying on the mannequin.

Additional bonus
If you’re occupied with how this pipe_fryum seems, listed below are a few examples with GLASS mannequin predictions.

5. Velocity outcomes
The variety of channels impacts solely the primary layer of the mannequin, the remainder stays unchanged. The velocity enchancment appears to be negligible, highlighting how the primary layer characteristic extraction is only a small a part of the calculations carried out by the fashions. GLASS exhibits a considerably noticeable enchancment, however on the similar time, it exhibits the worst metrics decline, so it requires warning if you wish to velocity it up by switching to 1 channel.

6. Conclusion
So how does utilizing grayscale photographs have an effect on visible anomaly detection? It relies upon, however RGB appears to be the safer guess. The impression varies relying on the mannequin and information. PatchCore and Reverse Distillation typically deal with grayscale inputs nicely, however it’s good to be extra cautious with FastFlow and particularly GLASS, which exhibits some velocity enchancment but additionally probably the most vital drop in efficiency metrics. If you wish to use grayscale enter, it’s good to take a look at and examine it with RGB in your particular information.
The jupyter pocket book with the Anomalib code: hyperlink.
Comply with creator on LinkedIn for extra on industrial visible anomaly detection.
References
1. C. Hughes, Switch Studying on Greyscale Pictures: Methods to High quality-Tune Pretrained Fashions (2022), towardsdatascience.com
2. S. Wehkamp, A sensible information to image-based anomaly detection utilizing Anomalib (2022), weblog.ml6.eu
3. A. Baitieva, Y. Bouaouni, A. Briot, D. Ameln, S. Khalfaoui, and S. Akcay. Past Educational Benchmarks: Important Evaluation and Greatest Practices for Visible Industrial Anomaly Detection (2025), CVPR Workshop on Visible Anomaly and Novelty Detection (VAND)
4. Y. Zou, J. Jeong, L. Pemula, D. Zhang, and O. Dabeer, SPot-the-Distinction Self-Supervised Pre-training for Anomaly Detection and Segmentation (2022), ECCV
5. S. Akcay, D. Ameln, A. Vaidya, B. Lakshmanan, N. Ahuja, and U. Genc, Anomalib (2022), ICIP