At times, you want to get rid of distortions caused by lights and shadows in an image. Normalizing the RGB values of an image can at times be a simple and effective way of achieving this.
When normalizing the RGB values of an image, you divide each pixel's value by the sum of the pixel's value over all channels. So if you have a pixel with intensitied R, G, and B in the respective channels... its normalized values will be R/S, G/S and B/S (where, S=R+G+B).
Here's an example (I tried this out when working on the soccer bot I made):
The upper image is the original shot taken from a camera. The lower image is its normalized version. It might not look pretty, but take note of some key changes in the image:
The shadows are the white edges have vanished
The black and white circles have become indistinguishable
The entire goal posts are not one solid colour.
Now this might not be the best picture to showoff normalized RGB. But it gets the point through. (If you find a better example, please let me know!!).
Writing code for this
We'll write a short function that will convert a given RGB image into a normalized RGB image. We begin by writing the function definition:
Now we create 3 more images. Each to hold the 3 channels of theimg.
Using the function we just created is simple. You give it an image in the RGB colour space. And it returns a new image in the normalized RGB form.
You're losing information
The normalized image can be represented using only 2 bytes per pixel (as opposed to 3 bytes per pixel in RGB). Here's how:
But you can represent B' like this as well:
So ultimately, all you need to store is the value of and . You can calculate the B' component from the other two. Physically, its this loss of information that "removes" the lighting information from the image.
Hopefully this article helped add a new tool to your arsenal of techniques and algorithms.
Utkarsh Sinha created AI Shack in 2010 and has since been working on computer vision and related fields. He is currently at Microsoft working on computer vision.
About AI Shack
Learn about the latest in AI technology with in-depth tutorials on vision and learning!