Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Converting Color to Grayscale Using ATL::CImage

0.00/5 (No votes)
5 Nov 2009 1  
Demonstrates how the ATL::CImage class can be used to do color-to-grayscale conversion on images.

Introduction

This is just a simple MFC application that demonstrates how you can use the ATL::CImage class to do color-to-grayscale conversion.

Background

Conversion is done by:

  1. obtaining the red, green, and blue values in each pixel's color information,
  2. adding together 30% of the red value, 59% of the green value, and 11% of the blue value,
  3. using the sum obtained in step 2 as the new red, green, and blue values.

Using the Code

There are two implementations for doing the conversion:

  • MakeGrayscale_Slow() --> simple but slow
  • MakeGrayscale_Fast() --> a little complicated but fast

Points of Interest

MakeGrayscale_Slow() and MakeGrayscale_Fast() produce different grayscales for the same color image. I have no idea why this happens. Anyone who knows?

History

  • 2009/11/06 - Uploaded this article

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here