Adjusting colors to match calibrated sample

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
aporthog
Posts: 37
Joined: 2012-05-30T08:24:46-07:00
Authentication code: 13

Adjusting colors to match calibrated sample

Post by aporthog » 2014-01-10T13:14:37-07:00

I'm trying to automatically adjust color images taken with two bookscanner cameras to match, more or less, the colors of the same page as scanned by a calibrated flat bed scanner. Here are the two images (Full size tiff versions are in http://ucblibrary4.berkeley.edu/~apollo ... ick/colors ):

Left camera:
Image

Calibrated flatbed:
Image

My idea was to use -level and -channel to adjust each RGB value as necessary to match the calibrated version. What I did was crop out a section of red, green, blue, and cyan from each image and a got the average RGB value from each of those 4 images.

red_left.tif:
Image

green_left.tif:
Image

etc...

Code: Select all

red_q13.tif: 229,34,45
green_q13.tif: 1,145,75
blue_q13.tif: 73,58,142
cyan_q13.tif: 0,159,222

red_left.tif: 179,31,29
green_left.tif: 65,161,41
blue_left.tif: 59,48,161
cyan_left.tif: 83,155,233
I naively thought that if the R channel of red_left.tif was off by 50 then the R channel of green_left.tif, blue_left.tif, cyan_left.tif would be off by about the same amount. But I can't see any rhyme or reason to how the channels differ for each image. I then created a 4 pixel long image of each color and took the average color of THAT to see if it gave me a satisfying values for each channel to adjust but the results are not good. The pages' whites are still a bit gray and dingy and the colors don't match the actual book pages.

I guess I have a lot to learn about color. I'm not looking for anything near perfection, just some adjustment I can make automatically to every single page image to make them close to real life. Any ideas?

snibgo
Posts: 12430
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Adjusting colors to match calibrated sample

Post by snibgo » 2014-01-10T14:13:49-07:00

The colour selectivity of the two scanners probably don't match, so an approach that regards the three channels as independant won't work.

Hald-clut is a better approach. This is a look-up table that specifies, for any input colour, the desired output colour. You know the desired transformations for 18 colours, so you need to interpolate the rest. This is quite complex and I don't have a script for this. fmw42 might have, at http://www.fmwconcepts.com/imagemagick/index.html . A compiled program may be more suitable.
snibgo's IM pages: im.snibgo.com

User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: Adjusting colors to match calibrated sample

Post by GreenKoopa » 2014-01-10T14:54:01-07:00

snibgo is right that this can be quite complex, so creating your own solution will only get you so close.

Adjustments may be easier in a cylindrical color space, i.e. one with hue. If you can achieve the adjustments you want using GIMP, Photoshop, etc, you can use snibgo's hald-clut suggestion to carry those adjustments over to ImageMagick. GIMP's hue-saturation tool, or Photoshop's equivalent, may help.

aporthog
Posts: 37
Joined: 2012-05-30T08:24:46-07:00
Authentication code: 13

Re: Adjusting colors to match calibrated sample

Post by aporthog » 2014-01-10T15:09:44-07:00

Thanks, I looked up Hald CLUT in the IM documentation and seems to be exactly what I want. I think creating a CLUT from the 18 colors I have and interpolating the rest is a task beyond me. What should work is doing the adjustment in Photoshop and generating a CLUT from that. I assume Photoshop can't export a Hald CLUT, but could I do the adjustment to my camera image, save it, then apply it to an identity CLUT I create with IM to create a new Hald CLUT?

User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: Adjusting colors to match calibrated sample

Post by GreenKoopa » 2014-01-10T15:15:50-07:00

Create a hald image using IM. Append it to your image and save in a lossless format. Make the adjustments in whatever program you like (including IM). Crop out the now adjusted hald image. Use IM and the adjusted hald color look-up table to apply the adjustment in batch to all your images.

aporthog
Posts: 37
Joined: 2012-05-30T08:24:46-07:00
Authentication code: 13

Re: Adjusting colors to match calibrated sample

Post by aporthog » 2014-01-10T17:07:16-07:00

Appending the clut, adjusting the image in PS, then cropping it back out again worked like a charm! Thanks everyone.

Post Reply