Click here to Skip to main content
15,884,022 members
Articles / Desktop Programming / MFC

Converting Color to Grayscale Using ATL::CImage

Rate me:
Please Sign up or sign in to vote.
3.07/5 (7 votes)
5 Nov 2009CPOL 37.5K   1.9K   9   6
Demonstrates how the ATL::CImage class can be used to do color-to-grayscale conversion on images.
Image 1

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Philippines Philippines
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 2 Pin
Mahdi Nejadsahebi1-Feb-14 23:07
Mahdi Nejadsahebi1-Feb-14 23:07 
GeneralMy vote of 1 Pin
SteveScanlon9-Nov-09 9:24
SteveScanlon9-Nov-09 9:24 
GeneralMy vote of 2 Pin
Nick Gorlov9-Nov-09 0:36
Nick Gorlov9-Nov-09 0:36 
General"Anyone who knows?" Pin
Axel Rietschin6-Nov-09 15:32
professionalAxel Rietschin6-Nov-09 15:32 
GeneralSome comments [modified] PinPopular
mluri6-Nov-09 0:08
mluri6-Nov-09 0:08 
GeneralRe: Some comments Pin
Darryl Bryk9-Aug-10 11:45
Darryl Bryk9-Aug-10 11:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.