Bitmap privedenie_k_odnomu_razmeru(Bitmap inpt, int width, int height) { int iCy = (int)(inpt.Height / 2d); int iCx = (int)(inpt.Width / 2d); int Cy = (int)(height / 2d); int Cx = (int)(width / 2d); int Vy = Cy - iCy; int Vx = Cx - iCx; byte[,,] input = RGB.BitmapToByteRgbNaive(inpt); byte[,,] result = new byte[3, height, width]; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { result[0, y, x] = 255; result[1, y, x] = 255; result[2, y, x] = 255; if (Vy <= y && y < inpt.Height + Vy && Vx <= x && x < inpt.Width + Vx) { result[0, y, x] = input[0, y - Vy, x - Vx]; result[1, y, x] = input[1, y - Vy, x - Vx]; result[2, y, x] = input[2, y - Vy, x - Vx]; } } } return(RGB.RgbToBitmapNaive(result)); }
private void ерозіяToolStripMenuItem_Click(object sender, EventArgs e) { byte[,,] rgb = RGB.BitmapToByteRgbNaive(Im[comboBox1.SelectedIndex]); int width = Im[comboBox1.SelectedIndex].Width, height = Im[comboBox1.SelectedIndex].Height; byte[,,] rgbN = new byte[3, height, width]; int Rozmir_maski_S = 1; int[,] S = StructElement(toolStripComboBox1.SelectedIndex); bool nullPoint = false; for (int y = Rozmir_maski_S; y < height - Rozmir_maski_S; y++) { for (int x = Rozmir_maski_S; x < width - Rozmir_maski_S; x++) { if (rgb[0, y, x] == 255) { nullPoint = false; for (int i = -Rozmir_maski_S; i <= Rozmir_maski_S; i++) { for (int j = -Rozmir_maski_S; j <= Rozmir_maski_S; j++) { if (S[1 + i, 1 + j] == 1) { if (rgb[0, y + i, x + j] == 0) { nullPoint = true; } } } } if (nullPoint == true) { rgbN[0, y, x] = RGB.Limit(0); rgbN[1, y, x] = RGB.Limit(0); rgbN[2, y, x] = RGB.Limit(0); } else { rgbN[0, y, x] = RGB.Limit(255); rgbN[1, y, x] = RGB.Limit(255); rgbN[2, y, x] = RGB.Limit(255); } } } } Im.Add(RGB.RgbToBitmapNaive(rgbN)); comboBox1.Items.Add(comboBox1.Text + "+E" + toolStripComboBox1.SelectedIndex); comboBox1.Text = comboBox1.Text + "+E" + toolStripComboBox1.SelectedIndex; label2.Text = "E" + toolStripComboBox1.SelectedIndex; }
private void testToolStripMenuItem_Click_1(object sender, EventArgs e) { int width = Im[comboBox1.SelectedIndex].Width, height = Im[comboBox1.SelectedIndex].Height; //byte[,,] rgb = InterpolIm_null(RGB.BitmapToByteRgbNaive(Im[comboBox1.SelectedIndex]), width,height,1); byte[,,] rgb = RGB.BitmapToByteRgbNaive(Im[comboBox1.SelectedIndex]); double phi = Convert.ToDouble(toolStripTextBox6.Text); Bitmap rgbN = korrectTest(rotIm(RGB.RgbToBitmapNaive(rgb), (float)phi)); double alpha = CalcOrientashion(RGB.BitmapToByteRgbNaive(rgbN), width, height); Test = rgbN; Im.Add(rgbN); comboBox1.Items.Add(comboBox1.Text + "+Povorot"); comboBox1.Text = comboBox1.Text + "+Povorot"; }
private void градаціяСірогоToolStripMenuItem_Click(object sender, EventArgs e) { byte[,,] rgb = RGB.BitmapToByteRgbNaive(Im[comboBox1.SelectedIndex]); int width = Im[comboBox1.SelectedIndex].Width, height = Im[comboBox1.SelectedIndex].Height; byte[,,] rgbN = new byte[3, height, width]; double buf = 0; dataGridView1.ColumnCount = width; dataGridView1.RowCount = height; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { buf = 0.2125 * rgb[0, y, x] + 0.7154 * rgb[1, y, x] + 0.0721 * rgb[2, y, x]; rgbN[0, y, x] = RGB.Limit(buf); rgbN[1, y, x] = RGB.Limit(buf); rgbN[2, y, x] = RGB.Limit(buf); if (rgbN[0, y, x] != 255) { dataGridView1.Rows[y].Cells[x].Value = Convert.ToString(rgbN[0, y, x]); } } } Etalon = RGB.RgbToBitmapNaive(rgbN); Im.Add(RGB.RgbToBitmapNaive(rgbN)); comboBox1.Items.Add(comboBox1.Text + "+GS"); comboBox1.Text = comboBox1.Text + "+GS"; label2.Text = "GS"; }
Bitmap korrectTest(Bitmap inpt) { Bitmap res; byte[,,] test = RGB.BitmapToByteRgbNaive(inpt); //byte[,,] testRes = new byte[3, res.Height, res.Width]; for (int y = 0; y < inpt.Height; y++) { for (int x = 0; x < inpt.Width; x++) { if (test[0, y, x] == 0 && test[1, y, x] == 0) { test[0, y, x] = 255; test[1, y, x] = 255; test[2, y, x] = 255; } if (test[0, y, x] == 0 && test[2, y, x] == 0) { test[0, y, x] = 255; test[1, y, x] = 255; test[2, y, x] = 255; } if (test[1, y, x] == 0 && test[2, y, x] == 0) { test[0, y, x] = 255; test[1, y, x] = 255; test[2, y, x] = 255; } } } res = RGB.RgbToBitmapNaive(test); return(res); }
private void повернутиЕталонНаКутToolStripMenuItem_Click(object sender, EventArgs e) { byte[,,] rgb = RGB.BitmapToByteRgbNaive(Im[comboBox1.SelectedIndex]); int width = Im[comboBox1.SelectedIndex].Width, height = Im[comboBox1.SelectedIndex].Height; byte[,,] rgbN = new byte[3, height + 2, width + 2]; byte[,] tmp = new byte[height + 2, width + 2]; double alpha = CalcOrientashion(rgb, width, height); double phi = Convert.ToDouble(toolStripTextBox6.Text); List <double> nY = new List <double>(); List <double> nX = new List <double>(); double dx = 0, dy = 0; int count = 0; int pidizri = 0; int nevirno = 0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (rgb[0, y, x] == 255 && rgb[1, y, x] == 255 && rgb[2, y, x] == 255) { ; } else { nX.Add(Math.Round((x - (int)(width / 2d)) * Math.Cos(phi * Math.PI / 180) + (y - (int)(height / 2d)) * Math.Sin(phi * Math.PI / 180), 4)); nY.Add(Math.Round(-1.0 * (x - (int)(width / 2d)) * Math.Sin(phi * Math.PI / 180) + (y - (int)(height / 2d)) * Math.Cos(phi * Math.PI / 180), 4)); //dx = Math.Abs(); count++; if (tmp[(int)(height / 2d) + (int)nY[nY.Count - 1], (int)(width / 2d) + (int)nX[nX.Count - 1]] == 0) { tmp[(int)(height / 2d) + (int)nY[nY.Count - 1], (int)(width / 2d) + (int)nX[nX.Count - 1]] = 1; } else { pidizri++; if ((int)(height / 2d) + (int)nY[nY.Count - 1] - 1 >= 0 && (int)(width / 2d) + (int)nX[nX.Count - 1] - 1 >= 0 && (int)(height / 2d) + (int)nY[nY.Count - 1] + 1 < height && (int)(width / 2d) + (int)nX[nY.Count - 1] + 1 < width) { if (tmp[(int)(height / 2d) + (int)nY[nY.Count - 1] - 1, (int)(width / 2d) + (int)nX[nX.Count - 1]] == 0)//-1,0 { tmp[(int)(height / 2d) + (int)nY[nY.Count - 1] - 1, (int)(width / 2d) + (int)nX[nX.Count - 1]] = 1; } else if (tmp[(int)(height / 2d) + (int)nY[nY.Count - 1], (int)(width / 2d) + (int)nX[nX.Count - 1] - 1] == 0)//0,-1 { tmp[(int)(height / 2d) + (int)nY[nY.Count - 1], (int)(width / 2d) + (int)nX[nX.Count - 1] - 1] = 1; } else if (tmp[(int)(height / 2d) + (int)nY[nY.Count - 1], (int)(width / 2d) + (int)nX[nY.Count - 1] + 1] == 0)//0,+1 { tmp[(int)(height / 2d) + (int)nY[nY.Count - 1], (int)(width / 2d) + (int)nX[nY.Count - 1] + 1] = 1; } else if (tmp[(int)(height / 2d) + (int)nY[nY.Count - 1] + 1, (int)(width / 2d) + (int)nX[nY.Count - 1]] == 0)//+1,0 { tmp[(int)(height / 2d) + (int)nY[nY.Count - 1] + 1, (int)(width / 2d) + (int)nX[nY.Count - 1]] = 1; } else if (tmp[(int)(height / 2d) + (int)nY[nY.Count - 1] - 1, (int)(width / 2d) + (int)nX[nY.Count - 1] - 1] == 0)//-1,-1 { tmp[(int)(height / 2d) + (int)nY[nY.Count - 1] - 1, (int)(width / 2d) + (int)nX[nY.Count - 1] - 1] = 1; } else if (tmp[(int)(height / 2d) + (int)nY[nY.Count - 1] - 1, (int)(width / 2d) + (int)nX[nY.Count - 1] + 1] == 0)//-1,+1 { tmp[(int)(height / 2d) + (int)nY[nY.Count - 1] - 1, (int)(width / 2d) + (int)nX[nY.Count - 1] + 1] = 1; } else if (tmp[(int)(height / 2d) + (int)nY[nY.Count - 1] + 1, (int)(width / 2d) + (int)nX[nY.Count - 1] - 1] == 0)//+1,-1 { tmp[(int)(height / 2d) + (int)nY[nY.Count - 1] + 1, (int)(width / 2d) + (int)nX[nY.Count - 1] - 1] = 1; } else if (tmp[(int)(height / 2d) + (int)nY[nY.Count - 1] + 1, (int)(width / 2d) + (int)nX[nY.Count - 1] + 1] == 0)//+1,+1 { tmp[(int)(height / 2d) + (int)nY[nY.Count - 1] + 1, (int)(width / 2d) + (int)nX[nY.Count - 1] + 1] = 1; } else { nevirno++; } } } } } } MessageBox.Show("Кіл. точок не фону = " + count.ToString()); MessageBox.Show("Pidozri= " + pidizri.ToString()); MessageBox.Show("Nevorno= " + nevirno.ToString()); count = 0; for (int y = 0; y < height + 2; y++) { for (int x = 0; x < width + 2; x++) { if (tmp[y, x] == 1) { rgbN[0, y, x] = 255; rgbN[1, y, x] = 255; rgbN[2, y, x] = 255; count++; } else { rgbN[0, y, x] = 0; rgbN[1, y, x] = 0; rgbN[2, y, x] = 0; } } } MessageBox.Show("Кіл. точок без пропусків на зобр = " + count.ToString()); Im.Add(RGB.RgbToBitmapNaive(rgbN)); comboBox1.Items.Add(comboBox1.Text + "+Povorot"); comboBox1.Text = comboBox1.Text + "+Povorot"; label2.Text = "Povorot"; }
private void однаГраницяToolStripMenuItem_Click(object sender, EventArgs e) { List <byte> ColorGREY = new List <byte>(); byte[,,] rgb = RGB.BitmapToByteRgbNaive(Im[comboBox1.SelectedIndex]); int width = Im[comboBox1.SelectedIndex].Width, height = Im[comboBox1.SelectedIndex].Height; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { ColorGREY.Add(RGB.Limit(0.2125 * rgb[0, y, x] + 0.7154 * rgb[1, y, x] + 0.0721 * rgb[2, y, x])); } } int Porig1GREY = otsuThreshold(ColorGREY, 4); byte[,,] rgbN = new byte[3, height, width]; double buf = 0; PersentBin = 0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { buf = 0.2125 * rgb[0, y, x] + 0.7154 * rgb[1, y, x] + 0.0721 * rgb[2, y, x]; if (buf <= Porig1GREY) { PersentBin++; rgbN[0, y, x] = RGB.Limit(255); rgbN[1, y, x] = RGB.Limit(255); rgbN[2, y, x] = RGB.Limit(255); } else { rgbN[0, y, x] = RGB.Limit(0); rgbN[1, y, x] = RGB.Limit(0); rgbN[2, y, x] = RGB.Limit(0); } //if (buf <= Porig1GREY) //{ // PersentBin++; // rgbN[0, y, x] = RGB.Limit(0); // rgbN[1, y, x] = RGB.Limit(0); // rgbN[2, y, x] = RGB.Limit(0); //} //else //{ // rgbN[0, y, x] = RGB.Limit(255); // rgbN[1, y, x] = RGB.Limit(255); // rgbN[2, y, x] = RGB.Limit(255); //} } } PersentBin /= (width * height); Im.Add(RGB.RgbToBitmapNaive(rgbN)); comboBox1.Items.Add(comboBox1.Text + "+Bin"); comboBox1.Text = comboBox1.Text + "+Bin"; label2.Text = "Bin"; label3.Text = Math.Round(PersentBin, 4).ToString(); }