Chris Evans
Chris Evans

Reputation: 71

Adjusting one image's exposure / white balance to match another (with PIL?)

I have a cheap stereo camera rig that I use for diving. Sometimes each camera white balances or sets exposure differently. Example:

http://www.chrisevans3d.com/temp/forums/left.jpg

http://www.chrisevans3d.com/temp/forums/right.jpg

Is there a way to do this with getting im.histogram() of each, making a diff or LUT then transforming one image to the other? How does the 'Match Color' feature of photoshop work?

I would like to release a free software kit for making gopro stereo cameras more useable, so any help would be great.

Upvotes: 7

Views: 8165

Answers (2)

gfxmonk
gfxmonk

Reputation: 8746

See: http://en.wikipedia.org/wiki/Histogram_matching. This deals with greyscale histogram matching, but you can do it per-channel on an RGB image.

I have an implementation that does pretty much that here:

https://github.com/gfxmonk/stereoscoper/blob/8eba4b819c2415d5218dc0c9c8e264750ef4fb8e/stereoscoper#L120

Given a left and right image, it computes the "averaged" histogram for them and adjusts each image's levels to match that average. You can instead make the left match the right or the right match the left, but I prefer not to have to choose.

Upvotes: 0

user
user

Reputation: 18569

Matching white balance is not a trivial task. A very basic method is to assume a gray world and scale the RGB channels of one image to match the average RGB values of another. This will fail easily when the scenes are biased towards a color (instead of gray). You can improve it further by rejecting dark/bright pixels etc. There are tonnes of papers on white balancing. Find an algorithm to estimate the color temperature of the image and then determine which one is more appropriate for the scene/camera settings & normalize the images.

It's a similar story with exposure i.e. adaptive algorithms identify region of interest in the image and match the average brightness.

I'd suggest, start with a simple algorithm and then improve as you encounter failures. Allow manual overrides also.

EDIT :

Worth a start : HP Adaptive White Balance

Tool for reading raw images + basic post processing : dcraw

Upvotes: 4

Related Questions