65.9K
CodeProject is changing. Read more.
Home

Converting Color to Grayscale Using ATL::CImage

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.07/5 (7 votes)

Nov 6, 2009

CPOL
viewsIcon

38232

downloadIcon

1894

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