首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用AForge将RGB值转换为YCbCr

如何使用AForge将RGB值转换为YCbCr
EN

Stack Overflow用户
提问于 2012-08-16 22:52:44
回答 2查看 2.4K关注 0票数 0

我正在尝试将RGB值转换为YCbCr颜色格式。使用Afroge库。但是它给出了这样的结果,对于Y: 0.611,Cb : 0.15,Cr:-0.18。这意味着所有的值都小于1。但我需要介于0- 255之间的值。这是我的代码。

代码语言:javascript
复制
        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();

请帮帮我。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-08-16 23:33:29

这些是YCrCb的标准范围

但是,您可以将结果重新缩放到0- 255范围内

代码语言:javascript
复制
    label4.Text = (ycrcb.Y *255).ToString();
    label5.Text = ((ycrcb.Cr + 0.5)*255).ToString();
    label6.Text = ((ycrcb.Cb + 0.5)*255).ToString();
票数 1
EN

Stack Overflow用户

发布于 2015-11-21 21:56:31

公式是:

代码语言:javascript
复制
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之间。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11989901

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档