private static int bfsSearch(Image <Gray, Byte> img, bool[,] vi, ConnectLevel conn, Point start, int color, int padding) { if (vi[start.Y, start.X]) { return(0); } var domain = new ConnectDomain(); Queue <Point> queue = new Queue <Point>(); queue.Enqueue(start); var dir = DirVec; while (queue.Count > 0) { Point p = queue.Dequeue(); if (vi[p.Y, p.X]) { continue; } vi[p.Y, p.X] = true; domain.Add(p); for (int i = 0; i < connect; ++i) { int ny = p.Y + dir[i, 1], nx = p.X + dir[i, 0]; if (ny < padding || ny >= img.Height - padding) { continue; } if (nx < padding || nx >= img.Width - padding) { continue; } if (vi[ny, nx]) { continue; // 提前判断一下,好选择加入哪个集合 } Point np = new Point(nx, ny); if (img[ny, nx].Intensity >= color) { queue.Enqueue(np); } else { conn.NotIn.Add(np); } } } conn.AddDomain(domain); return(domain.Area); }
public void AddDomain(ConnectDomain domain) { Domains.Add(domain); }
private static int bfsSearch(Image<Gray, Byte> img, bool[,] vi, ConnectLevel conn, Point start, int color, int padding) { if (vi[start.Y, start.X]) return 0; var domain = new ConnectDomain(); Queue<Point> queue = new Queue<Point>(); queue.Enqueue(start); var dir = DirVec; while (queue.Count > 0) { Point p = queue.Dequeue(); if (vi[p.Y, p.X]) continue; vi[p.Y, p.X] = true; domain.Add(p); for (int i = 0; i < connect; ++i) { int ny = p.Y + dir[i, 1], nx = p.X + dir[i, 0]; if (ny < padding || ny >= img.Height - padding) continue; if (nx < padding || nx >= img.Width - padding) continue; if (vi[ny, nx]) continue; // 提前判断一下,好选择加入哪个集合 Point np = new Point(nx, ny); if (img[ny, nx].Intensity >= color) { queue.Enqueue(np); } else { conn.NotIn.Add(np); } } } conn.AddDomain(domain); return domain.Area; }