Exemple #1
0
        public override object Clone()
        {
            var res = new BinaryProcessor(Width, Height);

            res.Image = (int[, ]) this.Image.Clone();
            return(res);
        }
 public void Mask(BinaryProcessor mask)
 {
     for (int x = 0; x < Width; x++)
     {
         for (int y = 0; y < Height; y++)
         {
             this.Image[x, y] *= mask.Image[x, y] / 255;
         }
     }
     return;
 }
 public void Layer(BinaryProcessor layer)
 {
     for (int x = 0; x < Width; x++)
     {
         for (int y = 0; y < Height; y++)
         {
             var val = layer.Image[x, y] + this.Image[x, y];
             this.Image[x, y] = (val > 255) ? 255 : val;
         }
     }
     return;
 }
 private void Max(BinaryProcessor image, int u, int v)
 {
     for (int x = 0; x < this.Width; x++)
     {
         for (int y = 0; y < this.Height; y++)
         {
             if (u + x >= 0 & u + x < this.Width & v + y >= 0 & v + y < this.Height)
             {
                 this[x + u, y + v] = Math.Max(this[x + u, y + v], image[x, y]);
             }
         }
     }
 }
Exemple #5
0
        public BinaryProcessor Threshold(int T)
        {
            var b = new BinaryProcessor(Width, Height);

            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    b.Image[x, y] = (this.Image[x, y] >= T) ? 255 : 0;
                }
            }
            return(b);
        }
Exemple #6
0
        public void And(BinaryProcessor Image2)
        {
            if (Image2.Height != this.Height || Image2.Width != this.Width)
            {
                throw new ArgumentException("Images should have same dimensions.");
            }

            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    this.Image[x, y] *= Image2.Image[x, y] / 255;
                }
            }
        }
        public override void Dilate(StructuringElement structure)
        {
            // We assume that the hotspot of the structuring element is in
            // the middle.
            var hotspotX = (int)(structure.Size) / 2;
            var hotspotY = (int)(structure.Size) / 2;
            var buffer   = new BinaryProcessor(this.Width, this.Height);

            for (int u = 0; u < structure.Size; u++)
            {
                for (int v = 0; v < structure.Size; v++)
                {
                    if (structure[u, v] > 0)
                    {
                        buffer.Max(this, u - hotspotX, v - hotspotY);
                    }
                }
            }
            this.Image = buffer.Image;
        }