Example #1
0
        public void DoFilter(FastBitmap bitmap)
        {
            float[,] buffer = new float[bitmap.Width, bitmap.Height];
            Parallel.For(0, bitmap.Height, j =>
            {
                for (int i = _size; i < bitmap.Width - _size; i++)
                {
                    float pix = 0;
                    for (int k = -_size; k < _size; k++)
                    {
                        pix += bitmap[i + k, j] * _coefficients[k + _size];
                    }
                    buffer[i, j] = pix / _sumCoef;
                }
            });

            Parallel.For(0, bitmap.Width, i =>
               {
               for (int j = _size; j < bitmap.Height - _size; j++)
               {
                   float pix = 0;
                   for (int k = -_size; k < _size; k++)
                   {
                       pix += buffer[i, j + k] * _coefficients[k + _size];
                   }
                   bitmap[(int)i, j] = (byte)(pix / _sumCoef);
               }
               });
        }
Example #2
0
 private int[] CountGistogram(FastBitmap bitmap)
 {
     int[] result = new int[256];
     for (int i = 0; i < bitmap.Width; i++)
     {
         for (int j = 0; j < bitmap.Height; j++)
         {
             result[bitmap[i, j]]++;
         }
     }
     return result;
 }
Example #3
0
        public void DoFilter(FastBitmap bitmap)
        {
            int[] gistogramm = CountGistogram(bitmap);

            int threshold = CountThreshold(gistogramm);

            Parallel.For(0, bitmap.Width, i =>
            {
                for (int j = 0; j < bitmap.Height; j++)
                {
                    bitmap[i, j] = (byte)(bitmap[i, j] < threshold ? 0 : 255);
                }
            });
        }
Example #4
0
        public void DoFilter(FastBitmap bitmap)
        {
            int width = bitmap.Width;
            int height = bitmap.Height;
            int[,] windowX = new int[,] { { -1, 0, 1 }, { -2, 0, 2 }, { -1, 0, 1 } };
            int[,] windowY = new int[,] { { 1, 2, 1 }, { 0, 0, 0 }, { -1, -2, -1 } };
            byte[,] buffer = new byte[width, height];
            Angulars = new double[width, height];

            Parallel.For(1, width - 1, i =>
              {
                  for (int j = 1; j < height - 1; j++)
                  {
                      int new_x = 0;
                      int new_y = 0;

                      for (int wi = -1; wi < 2; wi++)
                      {
                          for (int hj = -1; hj < 2; hj++)
                          {
                              new_x += windowX[wi + 1, hj + 1] * bitmap[i + hj, j + wi];
                              new_y += windowY[wi + 1, hj + 1] * bitmap[i + hj, j + wi];
                          }
                      }
                      double new_val = Math.Sqrt(new_x * new_x + new_y * new_y);
                      Angulars[i, j] = Math.Atan2(new_y, new_x);
                      if (new_val > 255) new_val = 255;
                      if (new_val < 0) new_val = 0;
                      buffer[i, j] = (byte)new_val;
                  }
              });
            Parallel.For(1, width - 1, i =>
            {
                for (int j = 1; j < height - 1; j++)
                {
                    bitmap[i, j] = buffer[i, j];
                }
            });
        }