private void Distribution_FormClosing(object sender, FormClosingEventArgs e) { MainForm.Ellipses.Clear(); PictureBox p = (PictureBox)PictureBox.FromHandle(MainForm.MPicture); p.Refresh(); PictureBox p2 = (PictureBox)PictureBox.FromHandle(MainForm.SPicture); p2.Refresh(); }
public void LoadToBitmap(IntPtr P) { PictureBox P2 = (PictureBox)PictureBox.FromHandle(P); Bitmap b = null; if (EdgeDetection == 0) { ImageConverter.BitmapFromBool(ref b, res, W, H); } else { ImageConverter.BitmapFromBool(ref b, Eres, W, H); } P2.Image = b; }
void Apply_Chosen(object sender, EventArgs e) { for (int i = 0; i < 10; i++) { if (sender.Equals(ApplyButton[i])) { bool [,] Mask = new bool[Ps[i].Image.Width, Ps[i].Image.Height]; ImageConverter.PictureBoxToImageBinary(Ps[i], Mask); PictureBox Main = (PictureBox)PictureBox.FromHandle(MainForm.MPicture); Bitmap b = (Bitmap)Main.Image; ImageConverter.ApplyMask(b, Mask, Ps[i].Image.Width, Ps[i].Image.Height); Main.Image = b; Main.Visible = true; } } }
static public List <int> GetAreas(MyByteColor[,] src, int w, int h, ProgressBar p1, int MinSize, Rectangle r, PictureBox main, double dydx, double PatLength) { p1.Value = 0; int pvalue = 0; int AreaToadd; List <int> answ = new List <int>(); bool[,] Visited = new bool[w, h]; int xst, xfin, yst, yfin; if (r.Bottom == -2) { xst = yst = 0; xfin = w; yfin = h; } else { xst = Math.Max(0, r.Left); xfin = Math.Min(w, r.Right); yst = Math.Max(r.Top, 0); yfin = Math.Min(r.Bottom, h); } p1.Maximum = (xfin - xst + 1) / 10; List <MyShortPoint> Boundary = new List <MyShortPoint>(); for (int x = xst; x < xfin; x++) { for (int y = yst; y < yfin; y++) { if (src[x, y].R == 255 && src[x, y].G == 0 && src[x, y].B == 0) { continue; } if (src[x, y].R == 0 && src[x, y].G == 0 && src[x, y].B == 0) { continue; } Boundary.Clear(); AreaToadd = AreaCalculator.GetArea(Visited, src, x, y, w, h, Boundary); int index = 0; if (AreaToadd >= MinSize) { // answ.Add(AreaToadd); AnyMatrix <Double> E = ValueGetter.GetBestFitEllipse(Boundary); double[] a = new double[6]; for (int i = 0; i < 6; i++) { a[i] = E[i, 0]; } a[1] /= 2; a[3] /= 2; a[4] /= 2; if ((a[1] * a[1] - a[0] * a[2]) == 0) { continue; } if ((a[0] - a[2]) * (a[0] - a[2]) + 4 * a[1] * a[1] < 0) { continue; } if ((a[0] * a[4] * a[4] + a[2] * a[3] * a[3] + a[5] * a[1] * a[1] - 2 * a[1] * a[3] * a[4] - a[0] * a[2] * a[5]) / ((a[1] * a[1] - a[0] * a[2]) * (Math.Sqrt((a[0] - a[2]) * (a[0] - a[2]) + 4 * a[1] * a[1]) - (a[0] + a[2]))) < 0) { continue; } double a1 = 2 * Math.Sqrt(2 * (a[0] * a[4] * a[4] + a[2] * a[3] * a[3] + a[5] * a[1] * a[1] - 2 * a[1] * a[3] * a[4] - a[0] * a[2] * a[5]) / ((a[1] * a[1] - a[0] * a[2]) * (Math.Sqrt((a[0] - a[2]) * (a[0] - a[2]) + 4 * a[1] * a[1]) - (a[0] + a[2])))); double a2 = 2 * Math.Sqrt(2 * (a[0] * a[4] * a[4] + a[2] * a[3] * a[3] + a[5] * a[1] * a[1] - 2 * a[1] * a[3] * a[4] - a[0] * a[2] * a[5]) / ((a[1] * a[1] - a[0] * a[2]) * (-Math.Sqrt((a[0] - a[2]) * (a[0] - a[2]) + 4 * a[1] * a[1]) - (a[0] + a[2])))); PictureBox p = (PictureBox)PictureBox.FromHandle(MainForm.MPicture); double dx = 1.0 * p.Image.Width / p.Size.Width; double dy = 1.0 * p.Image.Height / p.Size.Height; a1 /= dx; a2 /= dy; //get Angle-------------------------- double fi = 0; if (a[1] == 0 && a[0] < a[2]) { fi = 0; } if (a[1] == 0 && a[0] >= a[2]) { fi = Math.PI / 2; } if (a[1] != 0 && a[0] < a[2]) { fi = 1.0 / 2 * (Math.PI / 2 - Math.Atan((a[0] - a[2]) / a[1])); } if (a[1] != 0 && a[0] >= a[2]) { fi = 1.0 / 2 * (Math.PI - Math.Atan((a[0] - a[2]) / a[1])); } double a1y = a1 * Math.Sin(fi); double a1x = a1 * Math.Cos(fi); a1y *= dydx; double a2y = a2 * Math.Sin(fi); double a2x = a2 * Math.Cos(fi); a2y *= dydx; a1 = Math.Sqrt(a1x * a1x + a1y * a1y); a2 = Math.Sqrt(a2x * a2x + a2y * a2y); double div = MainForm.Nat_pat_size * PatLength; a1 /= div; a2 /= div; double Value = AreaToadd / (div * div) * Math.Sqrt(a1 * a2) * MainForm.Density; answ.Add((int)(Value * 1000)); if (MainForm.ShowBestFitEllipses) { if (main.Visible) { ValueGetter.DrawEllipse(a, Graphics.FromHwnd(MainForm.MPicture), dx, dy, true); } else { ValueGetter.DrawEllipse(a, Graphics.FromHwnd(MainForm.SPicture), dx, dy, true); } } } } pvalue++; if (pvalue == 10) { pvalue = 0; p1.Value++; } } return(answ); }
private void RefreshPicture() { PictureBox pt = (PictureBox)PictureBox.FromHandle(MainForm.MPicture); pictureBox1.Image = pt.Image; }