將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
提交
取消
