Batch convert many images to same brightness/contrast

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
mshort
Posts: 2
Joined: 2015-07-19T15:00:15-07:00
Authentication code: 1151

Batch convert many images to same brightness/contrast

Post by mshort »

One of the lightbulbs on our overhead scanner was dim, causing the left side of each scan to be darker than the right. Hundreds of books were scanned this way before the problem was identified. (I'm not involved in the scanning.) I was hoping there might be some way to batch convert the images, so that they're all the same uniform brightness.

Example left: http://dimenovels.lib.niu.edu/islandora ... J/download
Example right: http://dimenovels.lib.niu.edu/islandora ... J/download

Side-by-side view: http://dimenovels.lib.niu.edu/islandora ... 2/mode/2up

So far I've tried equalize and Fred's histomatch script, but without success. The images look more similar, but only by changing them a bright shade of orange. I'm almost completely unfamiliar with image processing, so I was hoping someone here might be able to point me in the right direction.

Version: 6.9.1
Platform: OS X Yosemite

Thanks!

Matthew Short
Metadata Librarian
Northern Illinois University
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Batch convert many images to same brightness/contrast

Post by snibgo »

I'm not sure what you are trying to do. Perhaps you want to lighten the left side so the paper is the same lightness as the right (but a different colour). If so, just multiply the channels by an appropriate factor.

At a rough guess, the left image is 10% darker. So we can make it 10% lighter:

Code: Select all

%IM%convert OBJDatastream.tif -evaluate Multiply 1.1 x.tif
A better estimate of the factor could be found by cropping a blank area from each page, converting to grayscale, and finding the mean. Divide one by the other, and that is the factor to use.
snibgo's IM pages: im.snibgo.com
mshort
Posts: 2
Joined: 2015-07-19T15:00:15-07:00
Authentication code: 1151

Re: Batch convert many images to same brightness/contrast

Post by mshort »

Thanks for your help. When viewed side-by-side, as in an open book, both pages should be the same color. Basically, I want to compensate for the fact that the left side was scanned with less light. I was focusing on brightness, but maybe I should be changing the color instead? Apologies for not articulating the problem very well. Your code helps some, but there's still a noticeable difference.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Batch convert many images to same brightness/contrast

Post by snibgo »

You might want to change all the pages to the same shade of gray. To get a gray, the three RGB colour channels need to have the same value.

Taking a sample from a blank part of each page, without any text:
ObjDatastream2 (the right page) is rgb(87%, 75%, 60%)
ObjDatastream is (the left page) rgb(75%, 71%, 57%)

We could make all the values the same as the right page Red channel, 87% gray.

To do that, we need to multiply each channel:
ObjDatastream is (the left page) rgb(1.16, 1.225, 1.526)
ObjDatastream2 (the right page) is rgb(1.0, 1.16, 1.45)

Code: Select all

convert ObjDatastream.tif -profile sRGB.icc -channel R -evaluate Multiply 1.16 -channel G -evaluate Multiply 1.225 -channel B -evaluate Multiply 1.526 +channel x1.tif

convert ObjDatastream2.tif -profile sRGB.icc -channel G -evaluate Multiply 1.16 -channel B -evaluate Multiply 1.45 +channel x2.tif
To increase legibility, we can gently increase contrast:

Code: Select all

convert ObjDatastream.tif -profile sRGB.icc -channel R -evaluate Multiply 1.16 -channel G -evaluate Multiply 1.225 -channel B -evaluate Multiply 1.526 +channel -sigmoidal-contrast 5,60%% x1.tif

convert ObjDatastream2.tif -profile sRGB.icc -channel G -evaluate Multiply 1.16 -channel B -evaluate Multiply 1.45 -sigmoidal-contrast 5,60%% +channel x2.tif
The left page, being mostly gray, more clearly shows colour, in this case a pink at the sides. This could also be removed.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Batch convert many images to same brightness/contrast

Post by fmw42 »

try my script textcleaner and convert them to gray via the -g option. See the link below to get to my web site
Post Reply