public static Bitmap CreateMarbleTexture(Bitmap img, double firstLevel, double preserveLevel)
        {
            Bitmap sourceImage = ImageUtil.convert(img, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            Texturer myFilter = new Texturer(new MarbleTexture(), firstLevel, preserveLevel); //Needs Expand

            return(myFilter.Apply(sourceImage));
        }
        public static Bitmap maskImage(Bitmap img, Bitmap mask)
        {
            Bitmap greyscale = ImageFilter.FilterImage(mask, Filters.filters["Greyscale"]);
            //greyscale = FormatUtil.convert(greyscale, PixelFormat.Format32bppArgb);

            Bitmap invert = ImageFilter.FilterImage(greyscale, Filters.filters["Invert"]);
            //invert = FormatUtil.convert(invert, PixelFormat.Format32bppArgb);

            Bitmap toAddMask = ImageUtil.convert(img, PixelFormat.Format32bppArgb);

            Bitmap withAlpha = ImageMultiFilter.RGBA_replaceChannel(toAddMask, null, null, null, invert);

            return(withAlpha);
            //return ImageMultiFilter.OverlayImages(img, withAlpha, 1, 1);
        }
Exemple #3
0
        public static Bitmap RGBFilter(Bitmap img, Interval R, Interval G, Interval B, Color C, Boolean Dir)
        {
            img = ImageUtil.convert(img, PixelFormat.Format32bppArgb);

            ColorFiltering colorFilter = new ColorFiltering();

            colorFilter.Red   = new IntRange((int)R.Min, (int)R.Max);
            colorFilter.Green = new IntRange((int)G.Min, (int)G.Max);
            colorFilter.Blue  = new IntRange((int)B.Min, (int)B.Max);

            colorFilter.FillOutsideRange = Dir;
            colorFilter.FillColor        = new RGB(C);
            Bitmap filteredImage = colorFilter.Apply(img);

            return(filteredImage);
        }
        public static Bitmap DrawEllipse(Bitmap img, Pen p, Rectangle rec)
        {
            Bitmap   canvas = ImageUtil.convert(img, PixelFormat.Format32bppArgb);
            Graphics gIMG   = Graphics.FromImage(canvas);
            //Pen pp = new Pen()
            Pen pp = new Pen(new SolidBrush(Color.Black), 10);

            gIMG.DrawEllipse(p, rec);
            //gIMG.DrawArc
            //gIMG.DrawCurve
            //gIMG.DrawRectangle
            //gIMG.DrawPolygon
            //gIMG.DrawPath
            //gIMG.DrawPath(pp, new GraphicsPath())
            return(canvas);
        }
        public static Bitmap combineImages(Bitmap img1, Bitmap img2, Bitmap valuesCombination)
        {
            Bitmap below  = ImageUtil.convert(img1, PixelFormat.Format24bppRgb);
            Bitmap over   = ImageUtil.convert(img2, PixelFormat.Format24bppRgb);
            Bitmap values = ImageUtil.convert(valuesCombination, PixelFormat.Format24bppRgb);

            values = Grayscale.CommonAlgorithms.RMY.Apply(values);

            TexturedMerge filter = new TexturedMerge(TextureTools.FromBitmap(values));

            filter.OverlayImage = over;

            below = filter.Apply(below);

            return(below);
        }
        public static Bitmap DrawShape(Bitmap img, List <Shape2D> shapes)
        {
            Bitmap   canvas = ImageUtil.convert(img, PixelFormat.Format32bppArgb);
            Graphics gIMG   = Graphics.FromImage(canvas);

            foreach (var s in shapes)
            {
                s.draw(gIMG);
            }
            //gIMG.DrawArc
            //gIMG.DrawCurve
            //gIMG.DrawRectangle
            //gIMG.DrawPolygon
            //gIMG.DrawPath
            //gIMG.DrawPath(pp, new GraphicsPath())
            return(canvas);
        }
Exemple #7
0
        public static Tuple <Bitmap, Bitmap, Bitmap, Bitmap> getARGBA(Bitmap img)
        {
            img = ImageUtil.convert(img, PixelFormat.Format32bppArgb);

            ExtractChannel myFilter = new ExtractChannel(RGB.R);
            Bitmap         R        = myFilter.Apply(img);

            myFilter = new ExtractChannel(RGB.G);
            Bitmap G = myFilter.Apply(img);

            myFilter = new ExtractChannel(RGB.B);
            Bitmap B = myFilter.Apply(img);

            myFilter = new ExtractChannel(RGB.A);
            Bitmap A = myFilter.Apply(img);

            return(new Tuple <Bitmap, Bitmap, Bitmap, Bitmap>(R, G, B, A));
        }
        public static Bitmap operationImages(Bitmap img1, Bitmap img2, int op)
        {
            img1 = ImageUtil.convert(img1, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            img2 = ImageUtil.convert(img2, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            Bitmap  filteredImage = img1;
            IFilter myFilter;

            if (op == Filters.mode["Add"])
            {
                myFilter      = new Add(img2);
                filteredImage = myFilter.Apply(img1);
            }
            else if (op == Filters.mode["Subtract"])
            {
                myFilter      = new Subtract(img2);
                filteredImage = myFilter.Apply(img1);
            }
            else if (op == Filters.mode["Intersect"])
            {
                myFilter      = new Intersect(img2);
                filteredImage = myFilter.Apply(img1);
            }
            else if (op == Filters.mode["Difference"])
            {
                myFilter      = new Difference(img2);
                filteredImage = myFilter.Apply(img1);
            }
            else if (op == Filters.mode["Merge"])
            {
                myFilter      = new Merge(img2);
                filteredImage = myFilter.Apply(img1);
            }
            else if (op == Filters.mode["Multiply"])
            {
                myFilter      = new Multiply(img2);
                filteredImage = myFilter.Apply(img1);
            }
            return(filteredImage);
        }
        public static Bitmap RGBA_replaceChannel(Bitmap img, Bitmap RChannel, Bitmap GChannel, Bitmap BChannel, Bitmap AChannel)
        {
            Bitmap NewIMG = ImageUtil.convert(img, PixelFormat.Format32bppArgb);

            if (RChannel != null)
            {
                RChannel = ImageUtil.convert(RChannel, PixelFormat.Format32bppArgb);
                RChannel = Grayscale.CommonAlgorithms.RMY.Apply(RChannel);
                ReplaceChannel myFilter = new ReplaceChannel(RGB.R, RChannel);
                img = myFilter.Apply(img);
            }

            if (GChannel != null)
            {
                GChannel = ImageUtil.convert(GChannel, PixelFormat.Format32bppArgb);
                GChannel = Grayscale.CommonAlgorithms.RMY.Apply(GChannel);
                ReplaceChannel myFilter = new ReplaceChannel(RGB.G, GChannel);
                img = myFilter.Apply(img);
            }

            if (BChannel != null)
            {
                BChannel = ImageUtil.convert(BChannel, PixelFormat.Format32bppArgb);
                BChannel = Grayscale.CommonAlgorithms.RMY.Apply(BChannel);
                ReplaceChannel myFilter = new ReplaceChannel(RGB.B, BChannel);
                img = myFilter.Apply(img);
            }

            if (AChannel != null)
            {
                AChannel = ImageUtil.convert(AChannel, PixelFormat.Format32bppArgb);
                AChannel = Grayscale.CommonAlgorithms.RMY.Apply(AChannel);
                ReplaceChannel myFilter = new ReplaceChannel(RGB.A, AChannel);
                img = myFilter.Apply(img);
            }

            return(img);
        }
Exemple #10
0
        public static Bitmap CreateBoundaryGradient(Bitmap img, Color Cc, List <Color> Ce, float factor)
        {
            Bitmap canvas = MatchColorImage(img, Color.White);

            canvas = ImageUtil.convert(canvas, PixelFormat.Format32bppArgb);
            Graphics  g      = Graphics.FromImage(canvas);
            Rectangle myRect = new Rectangle(0, 0, canvas.Width, canvas.Height);

            GraphicsPath path = new GraphicsPath();

            path.AddRectangle(myRect);
            PathGradientBrush pthGrBrush = new PathGradientBrush(path);

            //pthGrBrush.SetSigmaBellShape(factor);
            pthGrBrush.SetBlendTriangularShape(factor);

            pthGrBrush.CenterColor = Cc;
            Color[] colors = Ce.ToArray <Color>();
            pthGrBrush.SurroundColors = colors;

            g.FillRectangle(pthGrBrush, myRect);
            return(canvas);
        }
Exemple #11
0
        //Ellipsoid Gradient as well
        public static Bitmap CreateGradient(Bitmap img, Color Cs, Color Ce, float angle, float factor)
        {
            Bitmap canvas = MatchColorImage(img, Color.White);

            canvas = ImageUtil.convert(canvas, PixelFormat.Format32bppArgb);
            Graphics  g      = Graphics.FromImage(canvas);
            Rectangle myRect = new Rectangle(0, 0, canvas.Width, canvas.Height);

            myRect.Inflate(1, 1);
            LinearGradientBrush myBrush = new LinearGradientBrush(myRect, Cs, Ce, angle, true);

            Blend myBlend = new Blend();

            float[] relativeIntensities = { 0.0f, 0.5f, 1.0f };
            float[] relativePositions   = { 0.0f, factor, 1.0f };
            myBlend.Positions = relativePositions;
            myBlend.Factors   = relativeIntensities;

            myBrush.Blend = myBlend;

            g.FillRectangle(myBrush, 0, 0, canvas.Width, canvas.Height);

            return(canvas);
        }
Exemple #12
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);
        }