/* ANMS Харриса */ private void button7_Click(object sender, EventArgs e) { if (textBox8.Text != "") { try { int Npoints = Convert.ToInt32(textBox8.Text); Harris.ANMS(Npoints); Harris.ImageWithANMS.Draw(pictureBox17); Harris.ImageWithANMS.Save(BasePath + "Lab 3/HarrisANMS.png"); label19.Text = "Точек: " + Harris.NewPoints; } catch { MessageBox.Show("Введите данные корректно!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Введите данные!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/* Дескрипторы (Лаб 5)*/ private void button11_Click(object sender, EventArgs e) { if (textBox14.Text != "" && textBox13.Text != "" && textBox12.Text != "") { try { int HarrisRadius = Convert.ToInt32(textBox14.Text); double HarrisDolya = Convert.ToDouble(textBox13.Text); int Npoints = Convert.ToInt32(textBox12.Text); Img BegImg1 = new Img(GrayImg.GrayMatrix, IWidth, IHeight); /*-------------------------*/ int size = Convert.ToInt32(Math.Ceiling(Math.Sqrt(IWidth * IWidth + IHeight * IHeight))); Bitmap RotateBMP = new Bitmap(size, size, PixelFormat.Format32bppArgb); for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { RotateBMP.SetPixel(x, y, Color.White); } } int o = (size - IHeight) / 2; int oo = (size - IWidth) / 2; for (int y = o; y < IHeight + o; y++) { for (int x = oo; x < IWidth + oo; x++) { RotateBMP.SetPixel(x, y, GrayImg.Bitmap.GetPixel(x - oo, y - o)); } } RotateBMP = F.RotateImage(RotateBMP, 45.0F); Img BegImg2 = new Img(RotateBMP); /* * byte[,] SdvigMtx = F.Sdvig(TempImg.GrayMatrix, TempImg.Width, TempImg.Height, out int nWidth, out int nHeight, 0, -50); * TempImg = new Img(SdvigMtx, nWidth, nHeight); * * byte[,] ContrastMtx = F.Contrast(TempImg.GrayMatrix, TempImg.Width, TempImg.Height, -10); * Img BegImg2 = new Img(ContrastMtx, TempImg.Width, TempImg.Height); */ /*--------------------------*/ //Img BegImg2 = new Img(BasePath + "Temp/GrayImage.png"); BegImg1.Draw(pictureBox45); BegImg2.Draw(pictureBox43); Harris Harris1 = new Harris(BegImg1, HarrisRadius, HarrisDolya); Harris1.ANMS(Npoints); Harris Harris2 = new Harris(BegImg2, HarrisRadius, HarrisDolya); Harris2.ANMS(Npoints); Harris1.ImageWithANMS.Draw(pictureBox47); Harris2.ImageWithANMS.Draw(pictureBox46); Harris1.Descript5(); Harris2.Descript5(); int[] S = F.DescriptSootv5(Harris1, Harris2, 16 * 8, 0.8); int rst = 20; int h = Math.Max(Harris1.ImageWithANMS.Height, Harris2.ImageWithANMS.Height); Bitmap SootvBmp = new Bitmap(Harris1.ImageWithANMS.Width + Harris2.ImageWithANMS.Width + rst, h, PixelFormat.Format32bppArgb); for (int y = 0; y < Harris1.ImageWithANMS.Height; y++) { for (int x = 0; x < Harris1.ImageWithANMS.Width; x++) { SootvBmp.SetPixel(x, y, Harris1.ImageWithANMS.Bitmap.GetPixel(x, y)); } } for (int y = 0; y < h; y++) { for (int x = Harris1.ImageWithANMS.Width; x < Harris1.ImageWithANMS.Width + rst; x++) { SootvBmp.SetPixel(x, y, Color.White); } } for (int y = 0; y < Harris2.ImageWithANMS.Height; y++) { for (int x = Harris1.ImageWithANMS.Width + rst; x < Harris1.ImageWithANMS.Width + rst + Harris2.ImageWithANMS.Width; x++) { SootvBmp.SetPixel(x, y, Harris2.ImageWithANMS.Bitmap.GetPixel(x - (Harris1.ImageWithANMS.Width + rst), y)); } } Random rand = new Random(); Graphics g = Graphics.FromImage(SootvBmp); Pen pen; Point p1, p2; for (int i = 0; i < Harris1.NewPoints; i++) { if (S[i] != -1) { int ra = rand.Next(0, 101); if (ra >= 0 && ra < 20) { pen = new Pen(Brushes.Blue, 2); } else if (ra >= 20 && ra < 40) { pen = new Pen(Brushes.Green, 2); } else if (ra >= 40 && ra < 60) { pen = new Pen(Brushes.Aqua, 2); } else if (ra >= 60 && ra < 80) { pen = new Pen(Brushes.Yellow, 2); } else { pen = new Pen(Brushes.Violet, 2); } p1 = new Point(Harris1.IntPointsCoord[i, 1], Harris1.IntPointsCoord[i, 0]); p2 = new Point(Harris2.IntPointsCoord[S[i], 1] + (Harris1.ImageWithANMS.Width + rst), Harris2.IntPointsCoord[S[i], 0]); g.DrawLine(pen, p1, p2); } } pictureBox48.Image = SootvBmp; Harris1.ImageWithANMS.Save(BasePath + "Lab 5/HarrisANMS1.png"); Harris2.ImageWithANMS.Save(BasePath + "Lab 5/HarrisANMS2.png"); SootvBmp.Save(BasePath + "Lab 5/Result.png"); } catch { MessageBox.Show("Введите данные корректно!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Введите данные!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/* Дескрипторы (Лаб 4)*/ private void button10_Click(object sender, EventArgs e) { if (textBox11.Text != "" && textBox10.Text != "" && textBox9.Text != "") { try { int HarrisRadius = Convert.ToInt32(textBox11.Text); double HarrisDolya = Convert.ToDouble(textBox10.Text); int Npoints = Convert.ToInt32(textBox9.Text); Img BegImg1 = new Img(GrayImg.GrayMatrix, IWidth, IHeight); /*-------------------------*/ int size = Convert.ToInt32(Math.Ceiling(Math.Sqrt(IWidth * IWidth + IHeight * IHeight))); Bitmap RotateBMP = new Bitmap(size, size, PixelFormat.Format32bppArgb); for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { RotateBMP.SetPixel(x, y, Color.White); } } int o = (size - IHeight) / 2; int oo = (size - IWidth) / 2; for (int y = o; y < IHeight + o; y++) { for (int x = oo; x < IWidth + oo; x++) { RotateBMP.SetPixel(x, y, GrayImg.Bitmap.GetPixel(x - oo, y - o)); } } RotateBMP = F.RotateImage(RotateBMP, 5.0F); Img TempImg = new Img(RotateBMP); byte[,] SdvigMtx = F.Sdvig(TempImg.GrayMatrix, TempImg.Width, TempImg.Height, out int nWidth, out int nHeight, 0, -100); TempImg = new Img(SdvigMtx, nWidth, nHeight); byte[,] ContrastMtx = F.Contrast(TempImg.GrayMatrix, TempImg.Width, TempImg.Height, -10); Img BegImg2 = new Img(ContrastMtx, TempImg.Width, TempImg.Height); /*--------------------------*/ BegImg1.Draw(pictureBox30); BegImg2.Draw(pictureBox29); Harris Harris1 = new Harris(BegImg1, HarrisRadius, HarrisDolya); Harris1.ANMS(Npoints); Harris Harris2 = new Harris(BegImg2, HarrisRadius, HarrisDolya); Harris2.ANMS(Npoints); Harris1.ImageWithANMS.Draw(pictureBox42); Harris2.ImageWithANMS.Draw(pictureBox41); Harris1.Descript4(); Harris2.Descript4(); int[] S = F.DescriptSootv4(Harris1, Harris2, 8 * 16, 0.8); int rst = 20; int h = Math.Max(Harris1.ImageWithANMS.Height, Harris2.ImageWithANMS.Height); Bitmap SootvBmp = new Bitmap(Harris1.ImageWithANMS.Width + Harris2.ImageWithANMS.Width + rst, h, PixelFormat.Format32bppArgb); for (int y = 0; y < Harris1.ImageWithANMS.Height; y++) { for (int x = 0; x < Harris1.ImageWithANMS.Width; x++) { SootvBmp.SetPixel(x, y, Harris1.ImageWithANMS.Bitmap.GetPixel(x, y)); } } for (int y = 0; y < h; y++) { for (int x = Harris1.ImageWithANMS.Width; x < Harris1.ImageWithANMS.Width + rst; x++) { SootvBmp.SetPixel(x, y, Color.White); } } for (int y = 0; y < Harris2.ImageWithANMS.Height; y++) { for (int x = Harris1.ImageWithANMS.Width + rst; x < Harris1.ImageWithANMS.Width + rst + Harris2.ImageWithANMS.Width; x++) { SootvBmp.SetPixel(x, y, Harris2.ImageWithANMS.Bitmap.GetPixel(x - (Harris1.ImageWithANMS.Width + rst), y)); } } Graphics g = Graphics.FromImage(SootvBmp); Pen pen = new Pen(Brushes.Blue, 2); Point p1, p2; for (int i = 0; i < Harris1.NewPoints; i++) { if (S[i] != -1) { p1 = new Point(Harris1.IntPointsCoord[i, 1], Harris1.IntPointsCoord[i, 0]); p2 = new Point(Harris2.IntPointsCoord[S[i], 1] + (Harris1.ImageWithANMS.Width + rst), Harris2.IntPointsCoord[S[i], 0]); g.DrawLine(pen, p1, p2); } } pictureBox44.Image = SootvBmp; Harris1.ImageWithANMS.Save(BasePath + "Lab 4/HarrisANMS1.png"); Harris2.ImageWithANMS.Save(BasePath + "Lab 4/HarrisANMS2.png"); SootvBmp.Save(BasePath + "Lab 4/Result.png"); } catch { MessageBox.Show("Введите данные корректно!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Введите данные!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }