Answer the question
In order to leave comments, you need to log in
How to convert an image from RGB to YIQ using c#?
I tried to convert. Here is my code:
private void RGBtoYIQbutton_Click(object sender, EventArgs e)
{
int[] vector_yiq = new int[3];
double r, g, b, y, i, q;
Bitmap bmp = new Bitmap(pictureBox1.Image);
for (int x = 0; x < bmp.Width; x++)
{
for (int y = 0; y < bmp.Height; y++)
{
Color clr = bmp.GetPixel(x, y);
r = (double)clr.R / 255;
g = (double)clr.G / 255;
b = (double)clr.B / 255;
y = Convert.ToInt32((0.299 * r + 0.587 * g + 0.114 * b) * 100);
i = Convert.ToInt32((0.596 * r - 0.274 * g - 0.322 * b) * 100);
if (i < 0)
i = Convert.ToInt32((0.596 * r - 0.274 * g - 0.322 * b + 0.5957) * 100);
q = Convert.ToInt32((0.211 * r - 0.522 * g + 0.311 * b ) * 100);
if (q < 0)
q = Convert.ToInt32((0.211 * r - 0.522 * g + 0.311 * b + 0.5226) * 100);
Color pixelColor;
pixelColor = Color.FromArgb(y, i, q);
bmp.SetPixel(x, y, pixelColor);
}
}
pictureBox1.Image = bmp;
}
Answer the question
In order to leave comments, you need to log in
pixelColor = Color.FromArgb(y, i, q);
as you rightly pointed out on stackoverfow , you only need to use this method for RGB/RGBA. It does not know how to work directly with yiq .NET. Usually non-standard color spaces are used for intermediate transformations.
By the way, parameter i has range [-0.522, 0.522] and i [-0.596, 0.596].
In the course of the algorithm, you don’t need these ifs either, the coefficients do everything for you. For example:
i = 0.596 * r - 0.274 * g - 0.322 * b;
i = 0.596 * 0 - 0.274 * 1 - 0.322 * 1;
i = -0.596
hence you do not need any of these perversions with ifs.
p.s. Why are you multiplying by 100? Are you trying to adjust the values in such a way that FromArgb would eat them? You don't need to do this.
And what's the point if changing the color space doesn't change your color...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question