Converting Color to Grayscale Using ATL::CImage






3.07/5 (7 votes)
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:
- obtaining the red, green, and blue values in each pixel's color information,
- adding together 30% of the red value, 59% of the green value, and 11% of the blue value,
- 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 slowMakeGrayscale_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