void IBinarization.MedianFilter(System.Drawing.Bitmap srcImage, Infrastructure.TemplateType type)
        {
            Byte[] rgbBytes    = LockBits(srcImage, System.Drawing.Imaging.ImageLockMode.ReadWrite);
            Int32  singleWidth = RealWidth / 3;
            Int32  length      = singleWidth * Height;

            Byte[] tempb = new Byte[length];
            for (int i = 0; i < Height; i++)
            {
                for (int j = 0; j < singleWidth; j++)
                {
                    tempb[i * singleWidth + j] = rgbBytes[i * Width + j * 3];
                }
            }
            Byte[] resub;
            base.medianFilter(ref tempb, singleWidth, Height, type, out resub);

            for (int i = 0; i < Height; i++)
            {
                for (int j = 0; j < singleWidth; j++)
                {
                    rgbBytes[i * Width + j * 3]     = resub[i * singleWidth + j];
                    rgbBytes[i * Width + j * 3 + 1] = resub[i * singleWidth + j];
                    rgbBytes[i * Width + j * 3 + 2] = resub[i * singleWidth + j];
                }
            }
            UnlockBits(rgbBytes);
        }
示例#2
0
        public void StatisticFilter(System.Drawing.Bitmap srcImage, Infrastructure.TemplateType type, double thresholding)
        {
            Byte[] rgbBytes    = LockBits(srcImage, System.Drawing.Imaging.ImageLockMode.ReadWrite);
            Int32  singleWidth = RealWidth / 3;
            Int32  length      = singleWidth * Height;

            Byte[] tempb = new Byte[length];
            Byte[] tempg = new Byte[length];
            Byte[] tempr = new Byte[length];
            for (int i = 0; i < Height; i++)
            {
                for (int j = 0; j < singleWidth; j++)
                {
                    tempb[i * singleWidth + j] = rgbBytes[i * Width + j * 3];
                    tempg[i * singleWidth + j] = rgbBytes[i * Width + j * 3 + 1];
                    tempr[i * singleWidth + j] = rgbBytes[i * Width + j * 3 + 2];
                }
            }
            Byte[] resub, resug, resur;
            base.statisticFilter(ref tempb, singleWidth, Height, thresholding, type, out resub);
            base.statisticFilter(ref tempg, singleWidth, Height, thresholding, type, out resug);
            base.statisticFilter(ref tempr, singleWidth, Height, thresholding, type, out resur);

            for (int i = 0; i < Height; i++)
            {
                for (int j = 0; j < singleWidth; j++)
                {
                    rgbBytes[i * Width + j * 3]     = resub[i * singleWidth + j];
                    rgbBytes[i * Width + j * 3 + 1] = resug[i * singleWidth + j];
                    rgbBytes[i * Width + j * 3 + 2] = resur[i * singleWidth + j];
                }
            }
            UnlockBits(rgbBytes);
        }