MATLAB Answers


how to do color correction

Asked by Elysi Cochin on 11 Jan 2013
Latest activity Commented on by Walter Roberson
on 12 Sep 2016

I wanted to do Color correction in an image such that the image appears to be taken under a white light source..... please could someone help me......


3 Answers

Answer by Image Analyst
on 11 Jan 2013
 Accepted answer

One of the best ways is to take a photo of the X-rite ColorChecker chart. Then use a polynomial regression to fit each color channel to the desired colors, sch as the sRGB values of the color checker chart.

An alternative ad-hoc way is to locate the bright region of your image, and assume that should be white (red=green=blue), then linearly scale each color channel so that the gray level of the brightest pixels end up all the same (say they all = the mean of the 3 color channels in the bright portion). This is by far the easiest (but worst) way to color correct.

Of course there are more sophisticated ways, but I don't know how fancy you want to get.


I'm not sure what you mean by errors. What are the "true values"? The means will change from uncorrected to corrected because there is a color shift due to the white balancing procedure. Like I said, this is very crude and there are better methods that use combinations of the colors rather than doing each channel independently.

Fu-An Nung comments,

Excuse me. May I ask you a question about color balance a video?

Fu-An Nung, please open a new Question for that topic.

Answer by Jurgen
on 11 Jan 2013

I guess we just have to assume you are using a normal rgb format... What image analyst suggested was to use your knowledge of the image to identify a pixel or area(group of pixels) that should be white/gray. Lets say these pixels have on average a ratio of 100:50:25 for red:green:blue. Then you correct by doubling the green intensities and quadrupling the blue intensities of all pixels.

Another way often used in cameras is histogram based. It adjusts the shape of the red, green & blue histograms to make them more similar. The downside is if your scene has alot of red for example it will look unnatural.

  1 Comment

thank u very much

on 14 Oct 2013

Dear image analyst, Some questions regarding the first method you propose with the X-rite ColorChecker chart. I have used the original rgb values given by the manufacturer for each of the 3 channels for all the 24 blocks in the colorchecker.

Then i took an image with my camera with the x-rite on the scene and in order to find how these 24 colors are changing for each channel.

then i used polynomial regression for each of the 3 channels seperatly to crate an input-output relationship between the real and the distorted values for each of the 3 channels.

Lastly i apply all these input-output relationships for all the image pixels.

the final result it's not seem correct. Am i doing something wrong?

  1 Comment

That's basically it. I don't know what's wrong without seeing the code or images. Perhaps you can start a new Question on this and we'll get it figured out. Probably not until much later today because I'm teaching a color science course all day today. Post your images and code in a new question and I'll look at it when I can.

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!