Grayscale Revealed

Color photo changed to grayscale

Photo editing software seems magic sometimes in the way that it can switch a photo from color to black and white with a button click. Learning the code for this has pulled back the curtain on this magical process.

When the Red, Green, and Blue values for a given pixel (between 0-255) are the same, you get a gray tone.  This also might explain why scanners or other imaging equipment list color settings as 24 bit and grayscale is only one third the value at 8 bit. If only one number value is needed to determine the pixel color instead of three separate ones for each color channel in Red, Green, and Blue then you have one third of the data.

With the handy for-loop command, Nick Parlante taught us how to calculate an average value for each pixel in a color image and modify each channel to be the same value to change it to gray. Here is the average snippet of code that generated the value to set for each pixel in the loop:

avg = (pixel.getRed() + pixel.getGreen() + pixel.getBlue())/3;

Very fun!

Advertisements
This entry was posted in Digital Images and tagged . Bookmark the permalink.

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