예제 #1
0
        public static Bitmap rangeRGBFilter(Bitmap img, Color C, Color Ch, int T, Boolean Dir)
        {
            Tuple <Interval, Interval, Interval> ranges = ImageUtil.getColorRange(C, T);

            return(RGBFilter(img, ranges.Item1, ranges.Item2, ranges.Item3, Ch, Dir));
        }
예제 #2
0
        public static Bitmap FilterImage(Bitmap img, int filter)
        {
            Bitmap sourceImage = img;

            sourceImage = ImageUtil.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            IFilter myFilter;
            Bitmap  filteredImage = sourceImage;

            if (filter == Filters.filters["Greyscale"])
            {
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                filteredImage = sourceImage;
            }
            else if (filter == Filters.filters["Sepia"])
            {
                myFilter      = new Sepia();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["Invert"])
            {
                sourceImage   = ImageUtil.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                myFilter      = new Invert();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["RotateChannel"])
            {
                myFilter      = new RotateChannels();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["Threshold"])
            {
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                myFilter      = new Threshold();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["FloydFilter"])
            {
                FloydSteinbergColorDithering myReduction = new FloydSteinbergColorDithering();
                filteredImage = myReduction.Apply(sourceImage);
            }
            else if (filter == Filters.filters["OrderedDithering"])
            {
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                myFilter      = new OrderedDithering();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["Sharpen"])
            {
                myFilter      = new Sharpen();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["DifferenceEdgeDetector"])
            {
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                myFilter      = new DifferenceEdgeDetector();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["HomogenityEdgeDetector"])
            {
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                myFilter      = new HomogenityEdgeDetector();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["Sobel"])
            {
                sourceImage   = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
                myFilter      = new SobelEdgeDetector();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["Jitter"])
            {
                myFilter      = new Jitter(); //Needs Expand
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["OilPainting"])
            {
                sourceImage   = ImageUtil.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                myFilter      = new OilPainting(); //Needs Expand
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["TextureFiltering"])
            {
                sourceImage   = ImageUtil.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                myFilter      = new Texturer(new TextileTexture(), 1.0, 0.8); //Needs Expand
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["Median"])
            {
                sourceImage   = ImageUtil.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                myFilter      = new Median();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["Mean"])
            {
                myFilter      = new Mean();
                filteredImage = myFilter.Apply(sourceImage);
            }
            else if (filter == Filters.filters["Blur"])
            {
                myFilter      = new GaussianBlur();
                filteredImage = myFilter.Apply(sourceImage);
            }

            //Console.Write(filteredImage.PixelFormat.ToString());
            //Console.Write(sourceImage.PixelFormat.ToString());
            filteredImage = ImageUtil.convert(filteredImage, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            return(filteredImage);
        }