2012-08-16 32 views
0

我想將RGB值轉換爲YCbCr顏色格式。使用Afroge庫。但它給出了這樣的結果,對於Y:0.611,Cb:0.15,Cr:-0.18。這意味着所有的值< 1.但我需要的值在0 - 255.這是我的代碼。如何將RGB值轉換爲YCbCr使用AForge

 Bitmap bitmap = (Bitmap)pictureBox1.Image; 

     double xRatio = (double)bitmap.Width/(double)pictureBox1.Width; 
     double yRatio = (double)bitmap.Height/(double)pictureBox1.Height; 

     Color gotColor = bitmap.GetPixel((int)((double)mX * xRatio), (int)((double)mY * yRatio)); 
     label1.Text = (" R : " + gotColor.R); 
     label2.Text = (" G : " + gotColor.G); 
     label3.Text = (" B : " + gotColor.B); 

     YCbCr ycrcb = new YCbCr(); 
     RGB rgbcolor = new RGB(gotColor); 

     ycrcb.Y = YCbCr.FromRGB(rgbcolor).Y; 
     ycrcb.Cr = YCbCr.FromRGB(rgbcolor).Cr; 
     ycrcb.Cb = YCbCr.FromRGB(rgbcolor).Cb; 

     label4.Text = ycrcb.Y.ToString(); 
     label5.Text = ycrcb.Cr.ToString(); 
     label6.Text = ycrcb.Cb.ToString(); 

請幫幫我。

回答

1

這些都是爲YCrCb的標準範圍

然而,你可能只是重新調整的結果爲0 - 255範圍內

label4.Text = (ycrcb.Y *255).ToString(); 
    label5.Text = ((ycrcb.Cr + 0.5)*255).ToString(); 
    label6.Text = ((ycrcb.Cb + 0.5)*255).ToString(); 
+0

非常感謝。這是工作 !!! – mssb 2012-08-16 15:49:45

0

其計算公式爲:

Y = (byte)((0.299 * red) + (0.587 * green) + (0.114 * blue)); 
Cb = (byte)(128 - (0.168736 * red) + (0.331264 * green) + (0.5 * blue)); 
Cr = (byte)(128 + (0.5 * red) + (0.418688 * green) + (0.081312 * blue)); 

,你可以jpg格式的YCbCr。結果值分別爲0和255.