static PointF[,] SmoothOutOrientationMap(PointF[,] orientation, bool[,] mask) { const int radius = 1; var size = Point.SizeOf(mask); PointF[,] smoothed = size.Allocate <PointF>(); for (int y = 0; y < size.Y; ++y) { for (int x = 0; x < size.X; ++x) { if (mask[y, x]) { Rectangle neighbors = Rectangle.Between( new Point(Math.Max(0, x - radius), Math.Max(0, y - radius)), new Point(Math.Min(size.X, x + radius + 1), Math.Min(size.Y, y + radius + 1))); PointF sum = new PointF(); for (int ny = neighbors.Bottom; ny < neighbors.Top; ++ny) { for (int nx = neighbors.Left; nx < neighbors.Right; ++nx) { if (mask[ny, nx]) { sum += orientation[ny, nx]; } } } smoothed[y, x] = sum; } } } return(smoothed); }
static bool[,] ApplyVotingFilter(bool[,] input, int radius = 1, double majority = 0.51, int borderDist = 0) { var size = Point.SizeOf(input); Rectangle rect = new Rectangle(new Point(borderDist, borderDist), new Point(size.X - 2 * borderDist, size.Y - 2 * borderDist)); var output = size.Allocate <bool>(); for (int y = rect.RangeY.Begin; y < rect.RangeY.End; ++y) { for (int x = rect.Left; x < rect.Right; ++x) { Rectangle neighborhood = Rectangle.Between( new Point(Math.Max(x - radius, 0), Math.Max(y - radius, 0)), new Point(Math.Min(x + radius + 1, size.X), Math.Min(y + radius + 1, size.Y))); int ones = 0; for (int ny = neighborhood.Bottom; ny < neighborhood.Top; ++ny) { for (int nx = neighborhood.Left; nx < neighborhood.Right; ++nx) { if (input[ny, nx]) { ++ones; } } } double voteWeight = 1.0 / neighborhood.TotalArea; if (ones * voteWeight >= majority) { output[y, x] = true; } } } return(output); }
public Rectangle this[Point at] { get { return(Rectangle.Between(Corners[at], Corners[at.Y + 1, at.X + 1])); } }
public Rectangle this[int y, int x] { get { return(Rectangle.Between(Corners[y, x], Corners[y + 1, x + 1])); } }