private void button1_Click(object sender, EventArgs e) // Open image { if (PanelWithGrid != null) { PanelWithGrid.Dispose(); } label3.Visible = false; OpenFileDialog openFileDialog1 = new OpenFileDialog(); if (openFileDialog1.ShowDialog() == DialogResult.OK) { try { OrigBmp = new Bitmap(openFileDialog1.FileName); OpenFileName = openFileDialog1.FileName; } catch (Exception ex) { MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message); } } else { return; } BmpPictBox2 = new Bitmap(OrigBmp.Width, OrigBmp.Height, PixelFormat.Format24bppRgb); Point P = new Point(20, 150); label3.Visible = true; label3.Location = P; label3.Text = "Opened file: " + openFileDialog1.FileName; groupBox1.Visible = true; label7.Text = "Click one of the radio buttons in 'Areas of radius'"; label7.Visible = true; button3.Visible = false; label2.Visible = false; numericUpDown2.Visible = false; button4.Visible = false; button5.Visible = false; OrigIm = new CImage(OrigBmp.Width, OrigBmp.Height, 24); progressBar1.Maximum = 100; progressBar1.Value = 0; progressBar1.Step = 1; progressBar1.Visible = true; double ScaleX = (double)pictureBox2.Width / (double)OrigIm.width; double ScaleY = (double)pictureBox2.Height / (double)OrigIm.height; if (ScaleX < ScaleY) { Scale1 = ScaleX; } else { Scale1 = ScaleY; } marginX = (pictureBox2.Width - (int)(Scale1 * OrigIm.width)) / 2; marginY = (pictureBox2.Height - (int)(Scale1 * OrigIm.height)) / 2; denomProg = OrigIm.denomProg = progressBar1.Maximum / progressBar1.Step; OrigIm.nLoop = nLoop = 2; if (OrigBmp.PixelFormat == PixelFormat.Format8bppIndexed) { OrigIm.BitmapToImageOld(OrigBmp, this); } else if (OrigBmp.PixelFormat == PixelFormat.Format24bppRgb) { OrigIm.BitmapToImage(OrigBmp, this); } else { MessageBox.Show("We do not use this pixel format=" + OrigBmp.PixelFormat); return; } SigmaIm = new CImage(OrigBmp.Width, OrigBmp.Height, 24); if (PanelWithGrid != null) { PanelWithGrid.Dispose(); } pictureBox1.Image = OrigBmp; pictureBox2.Image = BmpPictBox2; progressBar1.Step = 1; OrigIm.denomProg = progressBar1.Maximum / progressBar1.Step; ExtremIm = new CImage(OrigBmp.Width, OrigBmp.Height, 24); EdgeIm = new CImage(OrigBmp.Width, OrigBmp.Height, 8); CombIm = new CImage(2 * OrigBmp.Width + 1, 2 * OrigBmp.Height + 1, 8); BmpPictBox1 = new Bitmap(OrigBmp.Width, OrigBmp.Height, PixelFormat.Format24bppRgb); g1 = Graphics.FromImage(BmpPictBox1); g2 = Graphics.FromImage(BmpPictBox2); label5.Visible = false; label6.Visible = false; progressBar1.Visible = false; OPEN = true; EDGES = false; POLY = false; label5.Visible = true; label5.Text = "Original image"; } //**************************** end Open image *************************************
private void button1_Click_1(object sender, EventArgs e) // Open image { button2.Visible = false; label2.Visible = false; numericUpDown1.Visible = false; button3.Visible = false; radioButton1.Visible = false; radioButton2.Visible = false; OpenFileDialog openFileDialog1 = new OpenFileDialog(); if (openFileDialog1.ShowDialog() == DialogResult.OK) { try { OrigBmp = new Bitmap(openFileDialog1.FileName); } catch (Exception ex) { MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message); } } else { return; } Point P = new Point(20, 126); label1.Location = P; label1.Text = "File " + openFileDialog1.FileName; label1.Visible = true; button2.Visible = true; label2.Visible = true; numericUpDown1.Visible = true; label3.Visible = true; label4.Visible = false; label5.Text = "Click 'Detect edges'"; label5.Visible = true; FileName = openFileDialog1.FileName; progressBar1.Maximum = 100; progressBar1.Value = 0; progressBar1.Step = 1; progressBar1.Visible = true; if (OrigBmp.Width < 300 || OrigBmp.Height < 300) { MessageBox.Show("The image " + FileName + " is too small: width=" + OrigBmp.Width + " height=" + OrigBmp.Height + ". No bicycle recognized."); return; } if (OrigBmp.PixelFormat == PixelFormat.Format8bppIndexed) { OrigIm = new CImage(OrigBmp.Width, OrigBmp.Height, 8); OrigIm.BitmapToImageOld(OrigBmp, this); } else if (OrigBmp.PixelFormat == PixelFormat.Format24bppRgb) { OrigIm = new CImage(OrigBmp.Width, OrigBmp.Height, 24); OrigIm.BitmapToImage(OrigBmp, this); if (OrigBmp.Width > 1200) // Resize { HelpIm = new CImage(OrigBmp.Width, OrigBmp.Height, 24); int Reduce = 2; if (OrigBmp.Width > 2400) { Reduce = 4; } HelpIm.FastAverageUni(OrigIm, Reduce / 2, this); width = (OrigBmp.Width + Reduce / 2) / Reduce; height = (OrigBmp.Height + Reduce / 2) / Reduce; OrigIm = new CImage(width, height, 24); OrigIm.Resize(HelpIm, OrigBmp.Width, OrigBmp.Height, 3, Reduce); //, ref width, ref height); } } else { MessageBox.Show("Form1: Inappropriate pixel format=" + OrigBmp.PixelFormat); return; } width = OrigIm.width; height = OrigIm.height; double ScaleX = (double)pictureBox2.Width / (double)OrigIm.width; double ScaleY = (double)pictureBox2.Height / (double)OrigIm.height; if (ScaleX < ScaleY) { Scale1 = ScaleX; } else { Scale1 = ScaleY; } marginX = (pictureBox2.Width - (int)(Scale1 * OrigIm.width)) / 2; marginY = (pictureBox2.Height - (int)(Scale1 * OrigIm.height)) / 2; OrigIm.nLoop = 2; SigmaIm = new CImage(OrigIm.width, OrigIm.height, 24); pictureBox1.Image = OrigBmp; progressBar1.Visible = false; progressBar1.Maximum = 100; progressBar1.Step = 1; OrigIm.denomProg = progressBar1.Maximum / progressBar1.Step; ExtremIm = new CImage(OrigIm.width, OrigIm.height, 24); EdgeIm = new CImage(OrigIm.width, OrigIm.height, 8); CombIm = new CImage(2 * OrigIm.width + 1, 2 * OrigIm.height + 1, 8); BmpPictBox2 = new Bitmap(width, height); g2Bmp = Graphics.FromImage(BmpPictBox2); pictureBox2.Image = BmpPictBox2; OPEN = true; }
private void button1_Click(object sender, EventArgs e) // Open image { label1.Visible = false; label2.Visible = false; label3.Visible = false; label4.Visible = false; label5.Visible = false; label8.Visible = false; button2.Visible = false; button3.Visible = false; button5.Visible = false; button8.Visible = false; numericUpDown1.Visible = false; numericUpDown8.Visible = false; OpenFileDialog openFileDialog1 = new OpenFileDialog(); if (openFileDialog1.ShowDialog() == DialogResult.OK) { try { OrigBmp = new Bitmap(openFileDialog1.FileName); FileName = openFileDialog1.FileName; } catch (Exception ex) { MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message); } } else { return; } label1.Visible = true; label2.Visible = true; label2.Text = "Opened image: " + openFileDialog1.FileName; label5.Visible = true; label5.Text = "Click 'Detect edges'"; button8.Visible = true; numericUpDown1.Visible = true; progressBar1.Maximum = 100; progressBar1.Value = 0; progressBar1.Step = 1; progressBar1.Visible = true; if (OrigBmp.PixelFormat == PixelFormat.Format8bppIndexed) { Indexed = true; } else { Indexed = false; } Resized = false; if (OrigBmp.Width < 500 && !Indexed) { ResBmp = new Bitmap(2 * OrigBmp.Width, 2 * OrigBmp.Height, OrigBmp.PixelFormat); Resized = true; for (int y = 0; y < ResBmp.Height; y++) { for (int x = 0; x < ResBmp.Width; x++) { ResBmp.SetPixel(x, y, OrigBmp.GetPixel(x / 2, y / 2)); } } } else { ResBmp = new Bitmap(OrigBmp.Width, OrigBmp.Height, OrigBmp.PixelFormat); //Format24bppRgb); } if (Resized) { OrigIm = new CImage(ResBmp.Width, ResBmp.Height, 24); if (ResBmp.PixelFormat == PixelFormat.Format8bppIndexed) { OrigIm.BitmapToImageOld(ResBmp, this); } else if (ResBmp.PixelFormat == PixelFormat.Format24bppRgb) { OrigIm.BitmapToImage(ResBmp, this); } else { MessageBox.Show("Form1: Inappropriate pixel format=" + ResBmp.PixelFormat); return; } } else { OrigIm = new CImage(OrigBmp.Width, OrigBmp.Height, 24); if (OrigBmp.PixelFormat == PixelFormat.Format8bppIndexed) { OrigIm.BitmapToImageOld(OrigBmp, this); } else if (OrigBmp.PixelFormat == PixelFormat.Format24bppRgb) { OrigIm.BitmapToImage(OrigBmp, this); } else { MessageBox.Show("Inappropriate pixel format=" + OrigBmp.PixelFormat); return; } } pictureBox1.Image = OrigBmp; label3.Visible = true; progressBar1.Visible = false; progressBar1.Maximum = 100; progressBar1.Step = 1; if (Resized) { WidthG = ResBmp.Width; HeightG = ResBmp.Height; } else { WidthG = OrigBmp.Width; HeightG = OrigBmp.Height; } SigmaIm = new CImage(WidthG, HeightG, 24); ExtremIm = new CImage(WidthG, HeightG, 24); EdgeIm = new CImage(WidthG, HeightG, 8); CombIm = new CImage(2 * WidthG + 1, 2 * HeightG + 1, 8); OPEN = true; EDGES = false; POLY = false; double ScaleX, ScaleY; ScaleX = (double)pictureBox2.Width / (double)OrigIm.width; ScaleY = (double)pictureBox2.Height / (double)OrigIm.height; if (ScaleX < ScaleY) { Scale1 = ScaleX; } else { Scale1 = ScaleY; } marginX = (pictureBox2.Width - (int)(Scale1 * OrigIm.width)) / 2; marginY = (pictureBox2.Height - (int)(Scale1 * OrigIm.height)) / 2; BmpPictBox2 = new Bitmap(ResBmp.Width, ResBmp.Height, PixelFormat.Format24bppRgb); g2Bmp = Graphics.FromImage(BmpPictBox2); pictureBox2.Image = BmpPictBox2; } //****************************** end Open image ***********************************