Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatic enhancement of scanned images

I'm developing a routine for automatic enhancement of scanned 35 mm slides. I'm looking for a good algorithm for increasing contrast and removing color cast. The algorithm will have to be completely automatic, since there will be thousands of images to process. These are a couple of sample images straight from the scanner, only cropped and downsized for web:

A_CroppedB_Cropped

I'm using the AForge.NET library and have tried both the HistogramEqualization and ContrastStretch filters. HistogramEqualization is good for maximizing local contrast but does not produce pleasing results overall. ContrastStretch is way better, but since it stretches the histogram of each color band individually, it sometimes produces a strong color cast:

A_Stretched

To reduce the color shift, I created a UniformContrastStretch filter myself using the ImageStatistics and LevelsLinear classes. This uses the same range for all color bands, preserving the colors at the expense of less contrast.

    ImageStatistics stats = new ImageStatistics(image);     int min = Math.Min(Math.Min(stats.Red.Min, stats.Green.Min), stats.Blue.Min);     int max = Math.Max(Math.Max(stats.Red.Max, stats.Green.Max), stats.Blue.Max);     LevelsLinear levelsLinear = new LevelsLinear();     levelsLinear.Input = new IntRange(min, max);     Bitmap stretched = levelsLinear.Apply(image); 

A_UniformStretched

The image is still quite blue though, so I created a ColorCorrection filter that first calculates the mean luminance of the image. A gamma correction value is then calculated for each color channel, so that the mean value of each color channel will equal the mean luminance. The uniform contrast stretched image has mean values R=70 G=64 B=93, the mean luminance being (70 + 64 + 93) / 3 = 76. The gamma values are calculated to R=1.09 G=1.18 B=0.80 and the resulting, very neutral, image has mean values of R=76 G=76 B=76 as expected:

A_UniformStretchedCorrected

Now, getting to the real problem... I suppose correcting the mean color of the image to grey is a bit too drastic and will make some images quite dull in appearance, like the second sample (first image is uniform stretched, next is the same image color corrected):

B_UniformStretchedB_UniformStretchedCorrected

One way to perform color correction manually in a photo editing program is to sample the color of a known neutral color (white/grey/black) and adjust the rest of the image to that. But since this routine has to be completely automatic, that is not an option.

I guess I could add a strength setting to my ColorCorrection filter, so that a strength of 0.5 will move the mean values half the distance to the mean luminance. But on the other hand, some images might do best without any color correction at all.

Any ideas for a better algoritm? Or some method to detect whether an image has a color cast or just has lots of some color, like the second sample?

like image 272
Anlo Avatar asked Jan 07 '13 21:01

Anlo


People also ask

How do I automate a scanned document?

The easiest way to automate the conversion of scanned files is to use PDF software that has in-built OCR capability. pdfDocs, for example, monitors folders in document repositories or local File Systems and automatically checks each new file for image-based documents to convert to a text-searchable PDF.

How can I improve the quality of a scanned document online?

You can use a smartphone, tablet, PC, Mac, or other device to scan a document or image and enhance it online. ScanWritr automatically detects margins, improves document quality, and removes shadows and other visual imperfections. This corrects distorted scans and improves their quality.


1 Answers

  • translated to hsv
  • V-layer is corrected by scaling values from (min,max) range to (0,255) range
  • assembled back to rgb
  • correcting R,G,B layers of result by same idea as the V-layer on second step

there is no aforge.net code, because it processed by php prototype code, but afaik there is no any problem to do such with aforge.net. results are:

enter image description hereenter image description here

like image 109
orrollo Avatar answered Oct 05 '22 21:10

orrollo