Click here to Skip to main content
Click here to Skip to main content

Converting Color to Grayscale Using ATL::CImage

, 5 Nov 2009
Rate this:
Please Sign up or sign in to vote.
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

daily insider

Philippines Philippines
No Biography provided

Comments and Discussions

 
GeneralMy vote of 2 PinmemberMahdi Nejadsahbei1-Feb-14 23:07 
GeneralMy vote of 1 PinmemberSteveScanlon9-Nov-09 9:24 
GeneralMy vote of 2 PinmemberNick Gorlov9-Nov-09 0:36 
General"Anyone who knows?" PinmemberAxel Rietschin6-Nov-09 15:32 
GeneralSome comments [modified] Pinmembermluri6-Nov-09 0:08 
GeneralRe: Some comments PinmemberDarryl Bryk9-Aug-10 11:45 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140814.1 | Last Updated 6 Nov 2009
Article Copyright 2009 by daily insider
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid