RGBness of an image

A looked upon this image and thought, “what a bluish image!”

And then it suddenly came to my mind. What can be a quantitative method of telling that this image is a blue image? This was the scheme I devised:

1. Get RGB value of every pixel in the image.
2. Replace the pixel with a true RED, GREEN or BLUE pixel depending on the weight of these color in the pixel.
ie replace (120,50,20) with (255,0,0)
3. Now calculate the weight of each RED, GREEN and BLUE color of the newly formed image.
4. ( For RGB value with equal wight, the pixel is not replaced with true R or G or B color but with equal  percentage of the color with equal weight. )

I wrote a small Python script to do the analysis task for me.

The image above obviously has high percentage of Blue color in it. The image replaced with true REG, GREEN, and BLUE color would look like:

(JPEG compression artifacts caused some irregular shades of red, green and blue.)

And the percentage of Red, Green and Blue are as follows:

`Redness:  14.2866575845 %`
`Greenness:  1.2399911032 %`
`Blueness: 84.4733513123 %`

So, quantitavely we can claim that the image is a BLUE image.

[The Python code: imageRGBness]

```#!/usr/bin/python
import Image

R_count = 0
G_count = 0
B_count = 0
total_count = 0

def checkColor(R,G,B):
global R_count, G_count, B_count, total_count
out = (0,0,0)

if R>=G:
if R>=B:
out = (R,0,0)
else:
out = (0,0,B)
elif G>=B:
out = (0,G,0)
else:
out = (0,0,B)

if R==G and out == (R,0,0):
out = (R,G,0)

if R==B and out == (R,0,0):
out = (R,0,B)

if G==B and out == (0,G,0):
out = (0,G,B)

R_count = R_count + R_add
G_count = G_count + G_add
B_count = B_count + B_add
return out

def compareRGB(pix,x,y):
pix_temp = pix
for i in range(0,y):
for j in range(0,x):
color = pix_temp[j,i]
R = color[0]
G = color[1]
B = color[2]

set = checkColor(R,G,B)

pix[j,i] = set

return pix

def openImage(filename):
global R_count, G_count, B_count, total_count
im = Image.open(filename)
size_of_image = im.size
x = size_of_image[0]
y = size_of_image[1]

compareRGB(pix, x, y)

im.save("test_out.jpg")
total_count = x * y

print "Redness: ", R_count/total_count*100
print "Greenness: ", G_count/total_count*100
print "Blueness", B_count/total_count*100

#start the script
openImage("test.jpg")
```

[image used : http://www.flickr.com/photos/sul4bh/5161722620/ ]

5 Responses to RGBness of an image

1. sul4bh says:

Thank you.

2. This site was… how do I say it? Relevant!! Finally I have found
something which helped me. Thanks!

3. Thank you for sharing your thoughts. I really appreciate your efforts
and I am waiting for your further write ups thanks once again.

4. It’s remarkable to visit this web page and reading the views
of all colleagues concerning this post, while I am also eager of getting knowledge.