Convert Color Images to Gray Images

The algorithm that can convert a color image to a gray image.

Advertisement

How to convert Color Images to Gray Images

There are some techniques to do this, and below is the one of them:

To convert color image to gray image convert all pixels like this pseudo code:


PIXEL clr;
COLOR old,new;

FOR  ALL clr in image DO
BEGIN
    old = clr.color;
    new.red = 0.5 * old.red  + 0.3 * old.green + 0.2 * old.blue;
    new.green = 0.5 * old.red  + 0.3 * old.green + 0.2 * old.blue;
    new.blue = 0.5 * old.red  + 0.3 * old.green + 0.2 * old.blue;
    clr.color = new;
END

For example:

A pixel with red = 94, green = 210, blue = 23
Convert to red = 115, green = 115, blue = 115

red = green = blue = 0.5*94 + 0.3*210 + 0.2*23 = 47+63+4.6 = 114.6 = 115

Have Fun

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top