public static void smooth(MyFloatColor[,] src, MyFloatColor[,] dst, double sigma, int width, int height, ProgressBar P1) { List <float> mask = new List <float>(MakeGaussMask(sigma)); normalize(mask); MyFloatColor[,] tmp = new MyFloatColor[width, height]; convolve_SumV(src, tmp, mask, width, height, P1); convolve_SumH(tmp, dst, mask, width, height, P1); }
private static float diff(MyFloatColor c1, MyFloatColor c2) { double c1R = Convert.ToDouble(c1.R) * 255; double c1G = Convert.ToDouble(c1.G) * 255; double c1B = Convert.ToDouble(c1.B) * 255; double c2R = Convert.ToDouble(c2.R) * 255; double c2G = Convert.ToDouble(c2.G) * 255; double c2B = Convert.ToDouble(c2.B) * 255; return((float)(Math.Sqrt((c1B - c2B) * (c1B - c2B) + (c1R - c2R) * (c1R - c2R) + (c1G - c2G) * (c1G - c2G)))); }
public static void SmoothRgbBitmap(ref Bitmap b, double sigma) { MyFloatColor [,] src = new MyFloatColor[b.Width, b.Height]; ImageConverter.BitmapToArrayRGBf(b, src); int w = b.Width; int h = b.Height; b = null; GC.Collect(); SmoothRgbArray(src, sigma, w, h); b = new Bitmap(w, h); ImageConverter.BitmapFromImageRGBf(ref b, src); }
public static void SmoothRgbArray(MyFloatColor[,] src, double sigma, int width, int height) { List <float> mask = new List <float>(MakeGaussMask(sigma)); normalize(mask); MyFloatColor[,] tmp = new MyFloatColor[width, height]; ProgressBar progressBar1 = (ProgressBar)ProgressBar.FromHandle(MainForm.ProgressBr); progressBar1.Maximum = 2 * height / 10; progressBar1.Value = 0; progressBar1.Minimum = 0; convolve_SumV(src, tmp, mask, width, height); convolve_SumH(tmp, src, mask, width, height); }
public static void Smooth(MyFloatColor[,] src, int w, int h, double sigma, ProgressBar P1, PictureBox Pct1) { GetImage(Pct1, src); MyFloatColor[,] bufdst = new MyFloatColor[w, h]; smooth(src, bufdst, sigma, w, h, P1); for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { src[i, j] = bufdst[i, j]; } } bufdst = null; }
static public int GetAreaW(List <MyShortPoint> Lt, bool[,] Mask, bool[,] Visited, MyFloatColor[,] src, double x1, double y1, ref int black, int w, int h) { /*More Complex Area calculator * Save each found pixel in Lt, * Mask-if Mask[i,j]==0 pixel is not calculated * result number of pixel */ int x = Convert.ToInt32(Math.Round(x1)); int y = Convert.ToInt32(Math.Round(y1)); MyFloatColor startColor = src[x, y]; int result = 0; Stack <pair> s = new Stack <pair>(); s.Push(new pair(x, y)); while (s.Count != 0) { pair top = s.Peek(); s.Pop(); if (top.x < 0 || top.x >= w) { continue; } if (top.y < 0 || top.y >= h) { continue; } if (eqf(src[top.x, top.y].R, -1.0f) || eqf(src[top.x, top.y].R, 1.0f) && eqf(src[top.x, top.y].G, 0.0f) && eqf(src[top.x, top.y].B, 0.0f)) { continue; } if (Visited[top.x, top.y]) { continue; } Lt.Add(new MyShortPoint(top.x, top.y)); result++; if (Mask[top.x, top.y] == false) { black++; } //src[top.x, top.y].R = -1.0f; Visited[top.x, top.y] = true; result++; if (checkBounds(top.x + 1, top.y, w, h)) { if (src[top.x + 1, top.y].G == startColor.G && src[top.x + 1, top.y].R == startColor.R && src[top.x + 1, top.y].B == startColor.B) { if (!Visited[top.x + 1, top.y]) { s.Push(new pair(top.x + 1, top.y)); } } } if (checkBounds(top.x - 1, top.y, w, h)) { if (src[top.x - 1, top.y].B == startColor.B && src[top.x - 1, top.y].G == startColor.G && src[top.x - 1, top.y].R == startColor.R) { if (!Visited[top.x - 1, top.y]) { s.Push(new pair(top.x - 1, top.y)); } } } if (checkBounds(top.x, top.y + 1, w, h)) { if (src[top.x, top.y + 1].R == startColor.R && src[top.x, top.y + 1].G == startColor.G && src[top.x, top.y + 1].B == startColor.B) { if (!Visited[top.x, top.y + 1]) { s.Push(new pair(top.x, top.y + 1)); } } } if (checkBounds(top.x, top.y - 1, w, h)) { if (src[top.x, top.y - 1].R == startColor.R && src[top.x, top.y - 1].G == startColor.G && src[top.x, top.y - 1].B == startColor.B) { if (!Visited[top.x, top.y - 1]) { s.Push(new pair(top.x, top.y - 1)); } } } } return(result); }