Exemple #1
0
        public static int[,] PointsFilter(Bitmap bm, IConvertion convertion)
        {
            int[,] MaTranAnhGoc = convertion.ConvertBitmapToMatrixGray(bm);
            int[] HistogramAnhGoc = convertion.ConvertMatrixToHistogram(MaTranAnhGoc);
            int   Thresholding    = getValueThreshoding(HistogramAnhGoc);

            int[,] MaTranAnhDaXuLy = new int[MaTranAnhGoc.GetLength(0), MaTranAnhGoc.GetLength(1)];
            for (int i = 0; i < MaTranAnhDaXuLy.GetLength(0) - 2; i++)
            {
                for (int j = 0; j < MaTranAnhDaXuLy.GetLength(1) - 2; j++)
                {
                    MaTranAnhDaXuLy[i + 1, j + 1] = getValuePointsFilter(i, j, MaTranAnhGoc);
                    if (MaTranAnhDaXuLy[i + 1, j + 1] < Thresholding)
                    {
                        MaTranAnhDaXuLy[i + 1, j + 1] = 0;
                    }
                    else
                    {
                        MaTranAnhDaXuLy[i + 1, j + 1] = 255;
                    }
                }
            }

            return(MaTranAnhDaXuLy);
        }
        public static int[,] Equalisation(IConvertion convertion, Bitmap bm)
        {
            int[,] MaTranAnh = convertion.ConvertBitmapToMatrixGray(bm);
            int[] Histogram = convertion.ConvertMatrixToHistogram(MaTranAnh);
            int   sum       = 0;

            int[] SumOfHist = new int[256];
            for (int i = 0; i < Histogram.Length; i++)
            {
                sum          = sum + Histogram[i];
                SumOfHist[i] = sum;
            }
            double area = bm.Width * bm.Height;
            double dm   = 255;
            int    k;

            int[,] MaTranAnhDaCanBangHistogram = new int[bm.Height, bm.Width];
            for (int i = 0; i < bm.Height; i++)
            {
                for (int j = 0; j < bm.Width; j++)
                {
                    k = MaTranAnh[i, j];
                    MaTranAnhDaCanBangHistogram[i, j] = (int)((dm / area) * SumOfHist[k]);
                }
            }
            return(MaTranAnhDaCanBangHistogram);
        }
 public static int[,] SobelFilter(Bitmap bm, IConvertion convertion)
 {
     int[,] MaTranAnhGoc         = convertion.ConvertBitmapToMatrixGray(bm);
     int[,] MaTranAnhDaXuLy      = new int[MaTranAnhGoc.GetLength(0), MaTranAnhGoc.GetLength(1)];
     int[,] MaTranQuaBoLocSobel1 = new int[MaTranAnhGoc.GetLength(0), MaTranAnhGoc.GetLength(1)];
     int[,] MaTranQuaBoLocSobel2 = new int[MaTranAnhGoc.GetLength(0), MaTranAnhGoc.GetLength(1)];
     for (int i = 0; i < MaTranAnhGoc.GetLength(0) - 2; i++)
     {
         for (int j = 0; j < MaTranAnhDaXuLy.GetLength(1) - 2; j++)
         {
             MaTranQuaBoLocSobel1[i + 1, j + 1] = getValueSobel1(i, j, MaTranAnhGoc);
             MaTranQuaBoLocSobel2[i + 1, j + 1] = getValueSobel2(i, j, MaTranAnhGoc);
         }
     }
     for (int i = 0; i < MaTranAnhGoc.GetLength(0) - 2; i++)
     {
         for (int j = 0; j < MaTranAnhDaXuLy.GetLength(1) - 2; j++)
         {
             MaTranAnhDaXuLy[i, j] = MaTranQuaBoLocSobel1[i, j] + MaTranQuaBoLocSobel2[i, j];
             if (MaTranAnhDaXuLy[i, j] < 0)
             {
                 MaTranAnhDaXuLy[i, j] = 0;
             }
             else if (MaTranAnhDaXuLy[i, j] > 255)
             {
                 MaTranAnhDaXuLy[i, j] = 255;
             }
         }
     }
     return(MaTranAnhDaXuLy);
 }
        public static int[,] fit(Bitmap bm, IConvertion convertion)
        {
            int[,] MaTranAnhGoc      = convertion.ConvertBitmapToMatrixGray(bm);
            int[,] MatrixBlack_White = convertion.ConvertMatrixGrayToMatrixBlack_White(MaTranAnhGoc);
            int[,] MaTranAnhDaXuLy   = new int[MaTranAnhGoc.GetLength(0), MaTranAnhGoc.GetLength(1)];
            for (int i = 0; i < MatrixBlack_White.GetLength(0); i++)
            {
                for (int j = 0; j < MatrixBlack_White.GetLength(1); j++)
                {
                    MaTranAnhDaXuLy[i, j] = 0;
                }
            }
            for (int i = 1; i < MatrixBlack_White.GetLength(0) - 1; i++)
            {
                for (int j = 1; j < MatrixBlack_White.GetLength(1) - 1; j++)
                {
                    if (isFit(i, j, MatrixBlack_White))
                    {
                        MaTranAnhDaXuLy[i, j] = 255;
                    }
                }
            }

            return(MaTranAnhDaXuLy);
        }
 public static int[,] MaxFilter(Bitmap bm, IConvertion convertion)
 {
     int[,] MaTranAnhGoc    = convertion.ConvertBitmapToMatrixGray(bm);
     int[,] MaTranAnhDaXuLy = new int[MaTranAnhGoc.GetLength(0), MaTranAnhGoc.GetLength(1)];
     for (int i = 0; i < MaTranAnhDaXuLy.GetLength(0) - 2; i++)
     {
         for (int j = 0; j < MaTranAnhDaXuLy.GetLength(1) - 2; j++)
         {
             MaTranAnhDaXuLy[i + 1, j + 1] = GetValueMax(j, i, MaTranAnhGoc);
         }
     }
     return(MaTranAnhDaXuLy);
 }
 public static int[,] PointProcessingLogarit(Bitmap bm, IConvertion convertion, double c)
 {
     int[,] MaTranAnhXam       = convertion.ConvertBitmapToMatrixGray(bm);
     int[,] MaTranAnhDaLogarit = new int[MaTranAnhXam.GetLength(0), MaTranAnhXam.GetLength(1)];
     for (int i = 0; i < MaTranAnhXam.GetLength(0); i++)
     {
         for (int j = 0; j < MaTranAnhXam.GetLength(1); j++)
         {
             MaTranAnhDaLogarit[i, j] = (int)(c * Math.Log10(1 + MaTranAnhXam[i, j] * 1.0));
         }
     }
     return(MaTranAnhDaLogarit);
 }
 public static int[,] PointProcessingNegative(Bitmap bm, IConvertion convertion)
 {
     int[,] MaTranAnhXam        = convertion.ConvertBitmapToMatrixGray(bm);
     int[,] MaTranAnhDaNegative = new int[MaTranAnhXam.GetLength(0), MaTranAnhXam.GetLength(1)];
     for (int i = 0; i < MaTranAnhXam.GetLength(0); i++)
     {
         for (int j = 0; j < MaTranAnhXam.GetLength(1); j++)
         {
             MaTranAnhDaNegative[i, j] = 255 - MaTranAnhXam[i, j];
         }
     }
     return(MaTranAnhDaNegative);
 }
        public static int[,] PointProcessingPower(Bitmap bm, IConvertion convertion, double c)
        {
            double lamda = 4;

            int[,] MaTranAnhXam     = convertion.ConvertBitmapToMatrixGray(bm);
            int[,] MaTranAnhDaPower = new int[MaTranAnhXam.GetLength(0), MaTranAnhXam.GetLength(1)];
            for (int i = 0; i < MaTranAnhXam.GetLength(0); i++)
            {
                for (int j = 0; j < MaTranAnhXam.GetLength(1); j++)
                {
                    MaTranAnhDaPower[i, j] = (int)(c * Math.Pow(MaTranAnhXam[i, j], lamda));
                }
            }
            return(MaTranAnhDaPower);
        }
 public static int[,] PointProcessingThresholding(Bitmap bm, IConvertion convertion, double threshold)
 {
     int[,] MaTranAnhXam            = convertion.ConvertBitmapToMatrixGray(bm);
     int[,] MaTranAnhDaThresholding = new int[MaTranAnhXam.GetLength(0), MaTranAnhXam.GetLength(1)];
     for (int i = 0; i < MaTranAnhXam.GetLength(0); i++)
     {
         for (int j = 0; j < MaTranAnhXam.GetLength(1); j++)
         {
             if (MaTranAnhXam[i, j] < threshold)
             {
                 MaTranAnhDaThresholding[i, j] = 0;
             }
             else
             {
                 MaTranAnhDaThresholding[i, j] = 255;
             }
         }
     }
     return(MaTranAnhDaThresholding);
 }
 public static int[,] MedianFilter(Bitmap bm, IConvertion convertion)
 {
     int[,] MaTranAnhGoc    = convertion.ConvertBitmapToMatrixGray(bm);
     int[,] MaTranAnhDaXuLy = new int[MaTranAnhGoc.GetLength(0), MaTranAnhGoc.GetLength(1)];
     for (int i = 0; i < MaTranAnhDaXuLy.GetLength(0) - 2; i++)
     {
         for (int j = 0; j < MaTranAnhDaXuLy.GetLength(1) - 2; j++)
         {
             MaTranAnhDaXuLy[i + 1, j + 1] = GetValueMedian(j, i, MaTranAnhGoc);
         }
     }
     //Console.WriteLine("Ma tran anh Median Filter");
     //for (int i = 0; i < MaTranAnhDaXuLy.GetLength(0); i++)
     //{
     //    for (int j = 0; j < MaTranAnhDaXuLy.GetLength(1) ; j++)
     //    {
     //        Console.Write(MaTranAnhDaXuLy[i,j] + "\t");
     //    }
     //    Console.WriteLine();
     //}
     return(MaTranAnhDaXuLy);
 }
Exemple #11
0
        public static int[,] LinesFilter(Bitmap bm, IConvertion convertion)
        {
            int[,] MaTranAnhGoc = convertion.ConvertBitmapToMatrixGray(bm);
            int[] HistogramAnhGoc = convertion.ConvertMatrixToHistogram(MaTranAnhGoc);
            int   Thresholding    = getValueThreshoding(HistogramAnhGoc);

            int[,] MaTranAnhDaXuLy = new int[MaTranAnhGoc.GetLength(0), MaTranAnhGoc.GetLength(1)];
            for (int i = 0; i < MaTranAnhDaXuLy.GetLength(0) - 2; i++)
            {
                for (int j = 0; j < MaTranAnhDaXuLy.GetLength(1) - 2; j++)
                {
                    MaTranAnhDaXuLy[i + 1, j + 1] = getValueHorizontalFilter(i, j, MaTranAnhGoc);
                }
            }
            for (int i = 0; i < MaTranAnhDaXuLy.GetLength(0) - 2; i++)
            {
                for (int j = 0; j < MaTranAnhDaXuLy.GetLength(1) - 2; j++)
                {
                    MaTranAnhDaXuLy[i + 1, j + 1] = getValue45Filter1(i, j, MaTranAnhGoc);
                }
            }
            for (int i = 0; i < MaTranAnhDaXuLy.GetLength(0) - 2; i++)
            {
                for (int j = 0; j < MaTranAnhDaXuLy.GetLength(1) - 2; j++)
                {
                    MaTranAnhDaXuLy[i + 1, j + 1] = getValueVerticalFilter(i, j, MaTranAnhGoc);
                }
            }
            for (int i = 0; i < MaTranAnhDaXuLy.GetLength(0) - 2; i++)
            {
                for (int j = 0; j < MaTranAnhDaXuLy.GetLength(1) - 2; j++)
                {
                    MaTranAnhDaXuLy[i + 1, j + 1] = getValue45Filter2(i, j, MaTranAnhGoc);
                }
            }

            return(MaTranAnhDaXuLy);
        }