开发者

Convert Image to Grayscale

How do I convert image to grayscale? I have the following quote from the wikipedia:

To convert any color to a grayscale representation of its luminance, first one must obtain the values of its red, green, and blue (RGB) primaries in linear intensity encodin开发者_如何学运维g, by gamma expansion. Then, add together 30% of the red value, 59% of the green value, and 11% of the blue value

Do I understand this quote correctly? I would do something like this:

For each pixel P
    For each color c in P
        P.c = round(
            (max(min((P.red^gamma), 255), 0) * 0.3) + 
            (max(min((P.blue^gamma), 255), 0) * 0.59) +
            (max(min((P.green^gamma), 255), 0) * 0.11))

Is it correct? What should gamma be?


Yes, that is correct. I will use Gamma 2.2. Depending of what you intend to use this grayscale image after that, Gamma of 1.0 can be faster and useful too.


I've always implemented with gamma = 1.0 (in other words, ignored).

You can find more about gamma correction here: http://en.wikipedia.org/wiki/Gamma_correction

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜