用 Mathematica 详细计算 RGB 到灰度级 [英] Detailed Calculation of RGB to Graylevel by Mathematica

查看:38
本文介绍了用 Mathematica 详细计算 RGB 到灰度级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过了

ColorConvert[img, "Grayscale"]

RGB 转换为灰度.我想知道 mathematica 的详细计算..

灰度=正方形(R^2+G^2+B^2)?

还是别的?

解决方案

我们可以通过用纯红、绿、蓝组成一个 3 像素的图像并进行转换来获得 mathematica 使用的确切值:

 lvec = First@图像数据[ColorConvert[图像[{{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}}],灰度"]]

<块引用>

{0.299, 0.587, 0.114}

请注意,这些是 http://en 的Rec. 601 luna 系数".wikipedia.org/wiki/Luma_%28video%29

在真实图像上测试:

 lena = ExampleData[{"TestImage", "Lena"}];lenag = ColorConvert[lena, "GrayScale"];ImageData@ImageApply[ lvec.# &, 莉娜 ] == 图像数据@lenag

<块引用>

正确

I tried

ColorConvert[img, "Grayscale"]

to convert the RGB to Graylevel. I am wondering the detailed calculation by mathematica..

Gray level= square(R^2+G^2+B^2)?

or something else?

解决方案

We can obtain the exact values used by mathematica by making up a 3 pixel image with pure red,green,blue and converting it:

 lvec = First@
         ImageData[
           ColorConvert[Image[{{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}}], 
             "GrayScale"]]

{0.299, 0.587, 0.114}

Note these are the "Rec. 601 luna coefficients" per http://en.wikipedia.org/wiki/Luma_%28video%29

Test this on a real image:

 lena = ExampleData[{"TestImage", "Lena"}];
 lenag = ColorConvert[lena, "GrayScale"];
 ImageData@ImageApply[ lvec.# & , lena ] == ImageData@lenag

True

这篇关于用 Mathematica 详细计算 RGB 到灰度级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆