Image White Balance

Introduction

White balance is used to remove unrealistic colour casts caused by different light source. It’s easy for human eyes to adjust what we see according to the light source of the current environment but it’s hard for the camera to adjust according to the lighting condition of the room. Sometimes, we refer that as colour temperature.

Colour temperature is correlated with the objects in a room.  It depends on the rate of absorbance of light of the objects in the room being photographed. A blackbody is something that absorbs all light not allowing all light to pass through, that’s also the reason why we always say black object absorbs light. On the other hand, white object reflects all light, so it’s often referred as “white light”.

Below shows an a graph representing the relative intensity vs wavelength at difference colour temperature for a Tungsten Lamp (Observe the non-linearity):

Image result for intensity at different color temperature

Below are the listing of colour temperature based on different environments: [source]

Color Temperature Light Source
1000-2000 K  Candlelight
2500-3500 K  Tungsten Bulb (household variety)
3000-4000 K  Sunrise/Sunset (clear sky)
4000-5000 K  Fluorescent Lamps
5000-5500 K  Electronic Flash
5000-6500 K  Daylight with Clear Sky (sun overhead)
6500-8000 K  Moderately Overcast Sky
9000-10000 K  Shade or Heavily Overcast Sky

Implementation

There’re few ways to implement white balance. My method is as follow:

  1. Obtain the histogram of the original image.
  2. Obtain the Cumulative Density Function (CDF) of that particular histogram.
  3. The histogram is then stretched based on a discard ratio which is based on the minimum and maximum of the CDF previously obtained. (I used 0.95 as my discard ratio)
  4. From step 3, we’re able to obtain the maximum and minimum value of our stretching range, thus we stretch our pixel value range with the following formula:
    Pixel = \frac{Original Pixel - min}{max - min}

The following is the result of my implementation:

Before white balance:

ori

After white balance:

wb

Source code of my implementation: imgWB

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s