Converting a colored to grayscale

Started by
5 comments, last by Scptre 21 years, 4 months ago
I am programming a small game for my computer science course and I was wondering if either Direct X or Windows GDI has a function that will let me convert a colored image to a grayscale image.
Advertisement
Sorry about the 2 posts. I hit the double click button on my mouse.
Um... I only saw one post. Yet, I hope double clicking doesn''t post two... (Tooko runs from current thread and returns to last post) Well, that was exausting.
I wonder why I scare so many people away...

The past was unknown, the future was predicted.
the future is just like the past, just later. - TANSTAAFL
Why would you need a GDI function to do it? Just calculate the luminance of the pixels. Thats all a greyscale image is.

( Luminance = (R+G+B)/3 )

Death of one is a tragedy, death of a million is just a statistic.
If at first you don't succeed, redefine success.
quote:Original post by python_regious
( Luminance = (R+G+B)/3 )


I remember that you need different factors (that together summs to 1.0) for R and G and B, because one is more intense than other. But I cant remember those factors.
Googled "rgb to luminance":
luminance = 0.3*red + 0.59*green + 0.11*blue;
quote:luminance = 0.3*red + 0.59*green + 0.11*blue;

A long time ago, I made a test image with three regions exactly red, blue and green, and I used Photoshop to convert it to grayscale. From that test, I got the same formula, and it seems to work pretty well.

There is something else you should be careful with: Gamma correction. If you start mixing values and in the end you just send them to your VGA, your medium-intensity colors are going to be too dark.

This topic is closed to new replies.

Advertisement