示例#1
0
        public static StructuringElement Cross(int length)
        {
            var element = new StructuringElement(length, length, new Point(length / 2, length / 2));

            for (int i = 0; i < length; i++)
            {
                element[i, length / 2] = element[length / 2, i] = BinaryPixel.Black;
            }
            return(element);
        }
示例#2
0
        public static StructuringElement Circle(int radius)
        {
            var origin        = new Point(radius, radius);
            var element       = new StructuringElement(radius * 2, radius * 2, origin);
            int squaredRadius = radius * radius;

            for (int x = 0; x < element.PixelWidth; x++)
            {
                for (int y = 0; y < element.PixelHeight; y++)
                {
                    element[x, y] = element.Origin.GetSquaredDistance(new Point(x, y)) < squaredRadius ? BinaryPixel.Black : BinaryPixel.White;
                }
            }
            return(element);
        }
示例#3
0
        public BinaryImage Erosion(StructuringElement structElement)
        {
            var res = new BinaryImage(PixelWidth, PixelHeight);

            for (int x = 0; x < PixelWidth; x++)
            {
                for (int y = 0; y < PixelHeight; y++)
                {
                    if (IsCovered(structElement, new Point(x, y)))
                    {
                        res[x, y] = BinaryPixel.Black;
                    }
                }
            }
            return(res);
        }
示例#4
0
 private bool IsCovered(StructuringElement structElement, Point originOnImage)
 {
     for (int dx = 0; dx < structElement.PixelWidth; dx++)
     {
         for (int dy = 0; dy < structElement.PixelHeight; dy++)
         {
             Point point = originOnImage - structElement.Origin + new Point(dx, dy);
             if (!IsPointInImage(point))
             {
                 continue;
             }
             if (structElement[dx, dy] == BinaryPixel.Black && this[point] != BinaryPixel.Black)
             {
                 return(false);
             }
         }
     }
     return(true);
 }
示例#5
0
 public BinaryImage Close(StructuringElement structElement)
 {
     return(Dilation(structElement).Erosion(structElement));
 }
示例#6
0
 public BinaryImage Open(StructuringElement structElement)
 {
     return(Erosion(structElement).Dilation(structElement));
 }