Exemplo n.º 1
0
        /// <summary>
        /// Applies filter to image
        /// </summary>
        /// <param name="bitmap">Bitmap</param>
        /// <param name="filter">Filter</param>
        private Bitmap ApplyFilter(Bitmap bitmap, Filter filter)
        {
            switch (filter.FilterType)
            {
            case FilterType.Binarization:
                return(BitmapHelper.Binarize(bitmap, (byte)filter.Parameters.ToInt32()));

            case FilterType.Brightness:
                return(BitmapHelper.SetBrightness(bitmap, filter.Parameters.ToInt32()));

            case FilterType.Contrast:
                return(BitmapHelper.SetContrast(bitmap, filter.Parameters.ToInt32()));

            case FilterType.GammaCorrection:
                return(BitmapHelper.SetGammaCorrection(bitmap, filter.Parameters.ToInt32()));

            case FilterType.AutoCrop:
                return(BitmapHelper.AutoCropBorders(bitmap));

            case FilterType.Crop:
                return(BitmapHelper.Crop(bitmap, (Rectangle)filter.Parameters));

            case FilterType.Dilation:
                return(BitmapHelper.Dilate(bitmap));

            case FilterType.Erosion:
                return(BitmapHelper.Erode(bitmap));

            case FilterType.PunchHolesRemoval:
                return(BitmapHelper.RemovePunchHoles(bitmap, (PunchHolesPositions)filter.Parameters));

            case FilterType.BlobsRemoval:
                return(BitmapHelper.RemoveBlobs(bitmap, (BlobsDimensions)filter.Parameters));

            case FilterType.LinesRemoval:
                return(BitmapHelper.RemoveLines(bitmap, filter.Parameters.ToEnum(LineRemoveOrientation.None)));

            case FilterType.StapleMarksRemoval:
                return(BitmapHelper.RemoveStapleMarks(bitmap));

            case FilterType.NoiseRemoval:
                return(BitmapHelper.RemoveNoise(bitmap));

            case FilterType.AutoDeskew:
                return(BitmapHelper.AutoDeskew(bitmap));

            case FilterType.Rotation:
                return(BitmapHelper.Rotate(bitmap, (float)filter.Parameters.ToInt32(), Color.Black));

            case FilterType.Sharpness:
                return(BitmapHelper.SetSharpness(bitmap, filter.Parameters.ToInt32()));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }