They gave this homework for school. I've been searching for two days but couldn't find it. In my application, The image selected from the computer should be converted from rgb
to yuv
and converted to gray color.
I did the conversion to yuv
below, but there are 2 more missing, so I couldn't convert to double
, so I made an int
. The color is not grey.
private void btn_piksel_Click(object sender, EventArgs e) { if (pct_goruntu.Image == null) return;
Bitmap goruntu = (Bitmap)pct_goruntu.Image;
Color ilkPiksel = goruntu.GetPixel(0, 0);
int genislik = goruntu.Width;
int yukseklik = goruntu.Height;
Bitmap yeniGoruntu = new Bitmap(genislik, yukseklik);
for (int sutun = 0; sutun < genislik; sutun++)
{
for (int satir = 0; satir < yukseklik; satir++)
{
Color piksel = goruntu.GetPixel(sutun, satir);
double Y = (0.257 * piksel.R) + (0.504 * piksel.G) + (0.098 * piksel.B) + 16;
double U = (-0.148 * piksel.R) + (-0.291 * piksel.G) + (0.439 * piksel.B) + 128;
double V = (0.439 * piksel.R) + (-0.368 * piksel.G) + (-0.071 * piksel.B) + 128;
Color hedefPiksel = Color.FromArgb(piksel.A, (int)Y, (int)U, (int)V);
yeniGoruntu.SetPixel(sutun, satir, hedefPiksel);
}
}
pct_hedef.Image = yeniGoruntu;
lbl_kirmizi.Text = "R: " + ilkPiksel.R.ToString();
lbl_yesil.Text = "G: " + ilkPiksel.B.ToString();
lbl_mavi.Text = "B: " + ilkPiksel.G.ToString();
}`