Exemplo n.º 1
0
        public static BMPReader convolution(BMPReader image, float[,] mat)
        {
            Color[,] image1 = image.Clone();
            for (int x = 0; x < image.width; x++)
            {
                for (int y = 0; y < image.height; y++)
                {
                    int   matx = mat.GetLength(0) / 2;
                    float R = 0f, G = 0f, B = 0f;
                    for (int i = -matx; i < matx; i++)
                    {
                        int maty = mat.GetLength(1) / 2;
                        for (int j = -maty; j < maty; j++)
                        {
                            if (IsValid(x - i, y - j, image.width, image.height))
                            {
                                int a = matx + i, b = maty + j;
                                R += mat[a, b] * image1[x - i, y - j].R;
                                G += mat[a, b] * image1[x - i, y - j].G;
                                B += mat[a, b] * image1[x - i, y - j].B;
                            }
                        }
                    }

                    image.set_pixel(x, y, Color.FromArgb(image1[x, y].A, Clamp((int)R, 0, 255), Clamp((int)G, 0, 255), Clamp((int)B, 0, 255)));
                }
            }
            return(image);
        }
Exemplo n.º 2
0
 public static BMPReader binarize(BMPReader image, int threshold)
 {
     for (int i = 0; i < image.height; i++)
     {
         for (int j = 0; j < image.width; j++)
         {
             Color color = image.get_pixel(j, i);
             if ((color.R + color.G + color.B) / 3 < threshold)
             {
                 image.set_pixel(j, i, Color.White);
             }
             else
             {
                 image.set_pixel(j, i, Color.Black);
             }
         }
     }
     return(image);
 }
Exemplo n.º 3
0
 public static BMPReader to_grey(BMPReader image)
 {
     for (int i = 0; i < image.height; i++)
     {
         for (int j = 0; j < image.width; j++)
         {
             Color color = image.get_pixel(j, i);
             int   grey  = (int)(color.R * .3f + color.G * .59 + color.B * .11);
             image.set_pixel(j, i, Color.FromArgb(grey, grey, grey, grey));
         }
     }
     return(image);
 }