} //**************************** end Open image ************************************* private void button2_Click(object sender, EventArgs e) // Edge detection { if (OPEN == false) { MessageBox.Show("Please open an image"); return; } if (!radioButton1.Checked && !radioButton2.Checked) { MessageBox.Show("Please click one of the radio buttons on the left side"); return; } progressBar1.Visible = true; progressBar1.Value = 0; progressBar1.Visible = true; SigmaIm.SigmaSimpleUni(OrigIm, 1, 30, this); ExtremIm.ExtremLightUni(SigmaIm, 3, this); Threshold = (int)numericUpDown1.Value; int NX = OrigIm.width; CombIm.LabelCellsSign(Threshold, ExtremIm, this); CombIm.CleanCombNew(81, this); int rv = CombIm.CheckComb(this); if (rv < 0) { Application.Exit(); } EdgeIm.CracksToPixel(CombIm); // The image "CombIm" gets the pixel values as lightnes (MaxC) of pixels of "ExtremIm" for (int y = 0; y < OrigIm.height; y++) { for (int x = 0; x < OrigIm.width; x++) { CombIm.Grid[2 * x + 1 + (2 * NX + 1) * (2 * y + 1)] = CombIm.MaxC(ExtremIm.Grid[3 * (x + NX * y) + 2], ExtremIm.Grid[3 * (x + NX * y) + 1], ExtremIm.Grid[3 * (x + NX * y) + 0]); } } EdgeIm.nLoop = nLoop; EdgeIm.denomProg = denomProg; EdgeIm.ImageToBitmapOld(BmpPictBox2, this); pictureBox2.Refresh(); progressBar1.Visible = false; label6.Visible = true; label6.Text = "Detected edges"; button3.Visible = true; label2.Visible = true; numericUpDown2.Visible = true; label7.Text = "Click 'Pollygons'"; label7.Visible = true; if (PanelWithGrid != null) { PanelWithGrid.Dispose(); } EDGES = true; } //*************************** end edge detection ******************************
private void button2_Click_1(object sender, EventArgs e) // Detect edges { if (!OPEN) { MessageBox.Show("Please open an image"); return; } progressBar1.Visible = true; progressBar1.Value = 0; if (OrigIm.N_Bits == 24) { SigmaIm.SigmaColor(OrigIm, 1, 30, this); ExtremIm.ExtremVarColor(SigmaIm, 2, this); // it was 2 } else { SigmaIm.SigmaNewM(OrigIm, 1, 30, this); ExtremIm.ExtremVar(SigmaIm, 2, this); // it was 2 } Threshold = (int)numericUpDown1.Value; int NX = OrigIm.width; CombIm.LabelCellsSign(Threshold, ExtremIm); CombIm.CleanCombNew(21, this); CombIm.CheckComb(7); for (int y = 0; y < OrigIm.height; y++) { for (int x = 0; x < OrigIm.width; x++) { if (ExtremIm.N_Bits == 24) { CombIm.Grid[2 * x + 1 + (2 * NX + 1) * (2 * y + 1)] = ExtremIm.Grid[1 + 3 * (x + NX * y)]; } else { CombIm.Grid[2 * x + 1 + (2 * NX + 1) * (2 * y + 1)] = SigmaIm.Grid[x + NX * y]; } } } EdgeIm.CracksToPixel(CombIm); EdgeBmp = new Bitmap(OrigIm.width, OrigIm.height, PixelFormat.Format24bppRgb); EdgeIm.ImageToBitmapOld(EdgeBmp, this); pictureBox2.Image = EdgeBmp; int nBits = CombIm.N_Bits; int maxL2 = 40000, maxV = 150000, maxArc = 40000, sizeX = EdgeIm.width / 8, sizeY = EdgeIm.height / 8, nx = EdgeIm.width / sizeX + 1, ny = EdgeIm.height / sizeY + 1, maxArcInPScell = 1200; L = new CListLines(maxL2, maxV, maxArc, nx, ny, maxArcInPScell, sizeX, sizeY); eps = 2.0; switch (width / 500) { case 0: eps = 1.01; break; case 1: eps = 1.05; break; case 2: eps = 1.20; break; case 3: eps = 1.70; break; } L.SearchPoly(ref CombIm, eps, this); bool RECT = true; int nArcs = L.MakeArcsTwo(pictureBox2, this); L.MakeDarts(this); bool ORI = false; RECT = false; int nPoint = 1; L.DrawArcs(ORI, RECT, nPoint, this); label4.Visible = true; int nEllipse = 0; //int Dir, rv = -1; Dir = L.FindEllipsesMode(SigmaIm, ListEllipse, ref nEllipse, this); label4.Text = "Recognized bicycle"; label4.Visible = true; label5.Visible = false; L.MakeDrawing(ListEllipse[0], ListEllipse[1], Dir, this); button3.Visible = true; radioButton1.Visible = true; radioButton2.Visible = true; label5.Text = "Click 'Save result'"; label5.Visible = true; if (MessReturn("Form1 258: Processing finished. Returning.") < 0) { return; } }
private void button4_Click(object sender, EventArgs e) // Detect edges { if (!OPEN) { MessageBox.Show("Please open an image"); return; } if (!IMPULSE) { MessageBox.Show("Please click 'Impulse noise'"); return; } if (!SEGMENTED) { MessageBox.Show("Please click 'Segment'"); return; } //pictureBox2.Visible = false; //label3.Visible = false; int CombWidth = 2 * SigmaIm.width + 1, CombHeight = 2 * SigmaIm.height + 1; CombIm = new CImage(CombWidth, CombHeight, 8); int Threshold = (int)numericUpDown3.Value; CombIm.LabelCellsSign(Threshold, ExtremIm, this); int jump, x, y; if (ExtremIm.height > 300) { jump = ExtremIm.height / 25; } else { jump = 3; } for (y = 0; y < ExtremIm.height; y++) { if (y % jump == jump - 1) { progressBar1.PerformStep(); } for (x = 0; x < ExtremIm.width; x++) { CombIm.Grid[2 * x + 1 + CombWidth * (2 * y + 1)] = Pal.Grid[x + fWidth * y]; } } CombIm.CleanCombNew(20, this); CombIm.CheckComb(7); EdgeIm = new CImage(fWidth, fHeight, 8); EdgeIm.CracksToPixel(CombIm, this); Bitmap EdgeBmp = new Bitmap(OrigIm.width, OrigIm.height, PixelFormat.Format24bppRgb); ImageToBitmapNew(EdgeIm, BmpPictBox2); // EdgeIm is always color image but BmpPictBox2 can be indexed pictureBox2.Image = BmpPictBox2; pictureBox2.Image = BmpPictBox2; label3.Text = "Detected edges"; label3.Visible = true; button5.Visible = true; label7.Text = "Click 'Encode'"; label7.Visible = true; progressBar1.Visible = false; DETECTED = true; } //***************************** end Detect edges *******************************