将RGB转换为灰度/灰度当从RGB转换为灰度时,应该使用R、G和B通道的特定权重。这些重量是:0.2989,0.5870,0.1140。据说,造成这种情况的原因是人类对这三种颜色的不同感知/感受。有时还会说,这些是用来计算NTSC信号的值。然而,我并没有在网上找到一个很好的参考资料。这些价值观的来源是什么?另见前几个问题:这里和这里.
3 回答
元芳怎么了
TA贡献1798条经验 获得超7个赞
unsigned int *pntrBWImage=(unsigned int*)..data pointer..; //assumes 4*width*height bytes with 32 bits i.e. 4 bytes per pixel unsigned int fourBytes; unsigned char r,g,b; for (int index=0;index<width*height;index++) { fourBytes=pntrBWImage[index];//caches 4 bytes at a time r=(fourBytes>>16); g=(fourBytes>>8); b=fourBytes; I_Out[index] = (r >>2)+ (g>>1) + (b>>2); //This runs in 0.00065s on my pc and produces slightly darker results //I_Out[index]=((unsigned int)(r+g+b))/3; //This runs in 0.0011s on my pc and produces a pure average }
添加回答
举报
0/150
提交
取消