private Bitmap reducedColor(Bitmap image, int numColors) { // create color image quantization routine ColorImageQuantizer ciq = new ColorImageQuantizer(new MedianCutQuantizer()); // create 16 colors table Color[] colorTable = ciq.CalculatePalette(image, numColors); // create dithering routine FloydSteinbergColorDithering dithering = new FloydSteinbergColorDithering(); dithering.ColorTable = colorTable; // apply the dithering routine Bitmap newImage = dithering.Apply(image); return(newImage); }
public static Bitmap FloydSteinbergColorDithering(Bitmap bmp, int value) { // create color image quantization routine ColorImageQuantizer ciq = new ColorImageQuantizer(new MedianCutQuantizer()); // create 16 colors table Color[] colorTable = ciq.CalculatePalette(bmp, value); // create dithering routine FloydSteinbergColorDithering dithering = new FloydSteinbergColorDithering(); dithering.ColorTable = colorTable; // apply the dithering routine Bitmap newImage = dithering.Apply(bmp); return(newImage); }
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); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object can be used to retrieve data from input parameters and /// to store data in output parameters.</param> protected override void SolveInstance(IGH_DataAccess DA) { Bitmap sourceImage = null; DA.GetData(0, ref sourceImage); string filter = ""; DA.GetData(1, ref filter); sourceImage = ImageUtilities.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format32bppArgb); IFilter myFilter; Bitmap filteredImage = sourceImage; //Grayscale.CommonAlgorithms.Y.Apply switch (filter) { case "Greyscale": Console.Write("Applying: " + filter); sourceImage = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage); filteredImage = sourceImage; break; case "Sepia": Console.Write("Applying: " + filter); myFilter = new Sepia(); filteredImage = myFilter.Apply(sourceImage); break; case "Invert": Console.Write("Applying: " + filter); sourceImage = ImageUtilities.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb); myFilter = new Invert(); filteredImage = myFilter.Apply(sourceImage); break; case "RotateChannel": Console.Write("Applying: " + filter); myFilter = new RotateChannels(); filteredImage = myFilter.Apply(sourceImage); break; case "Threshold": //Need Extended Version Console.Write("Applying: " + filter); sourceImage = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage); myFilter = new Threshold(); filteredImage = myFilter.Apply(sourceImage); break; case "FloydFilter": Console.Write("Applying: " + filter); //sourceImage = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage); //myFilter = new FloydSteinbergColorDithering(); FloydSteinbergColorDithering myReduction = new FloydSteinbergColorDithering(); filteredImage = myReduction.Apply(sourceImage); //filteredImage = myFilter.Apply(sourceImage); break; case "OrderedDithering": Console.Write("Applying: " + filter); sourceImage = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage); myFilter = new OrderedDithering(); filteredImage = myFilter.Apply(sourceImage); break; case "Sharpen": Console.Write("Applying: " + filter); myFilter = new Sharpen(); filteredImage = myFilter.Apply(sourceImage); break; case "DifferenceEdgeDetector": Console.Write("Applying: " + filter); sourceImage = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage); myFilter = new DifferenceEdgeDetector(); filteredImage = myFilter.Apply(sourceImage); break; case "HomogenityEdgeDetector": Console.Write("Applying: " + filter); sourceImage = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage); myFilter = new HomogenityEdgeDetector(); filteredImage = myFilter.Apply(sourceImage); break; case "Sobel": Console.Write("Applying: " + filter); sourceImage = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage); myFilter = new SobelEdgeDetector(); filteredImage = myFilter.Apply(sourceImage); break; case "Jitter": Console.Write("Applying: " + filter); myFilter = new Jitter(); //Needs Expand filteredImage = myFilter.Apply(sourceImage); break; case "OilPainting": Console.Write("Applying: " + filter); myFilter = new OilPainting(); //Needs Expand filteredImage = myFilter.Apply(sourceImage); break; case "TextureFiltering": Console.Write("Applying: " + filter); sourceImage = ImageUtilities.convert(sourceImage, System.Drawing.Imaging.PixelFormat.Format24bppRgb); myFilter = new Texturer(new TextileTexture(), 1.0, 0.8); //Needs Expand filteredImage = myFilter.Apply(sourceImage); break; case "Median": Console.Write("Applying: " + filter); myFilter = new Median(); filteredImage = myFilter.Apply(sourceImage); break; case "Mean": Console.Write("Applying: " + filter); myFilter = new Mean(); filteredImage = myFilter.Apply(sourceImage); break; case "Blur": //Need Extended Version Console.Write("Applying: " + filter); myFilter = new GaussianBlur(); filteredImage = myFilter.Apply(sourceImage); break; default: Console.Write("No Filter"); break; } Console.Write(filteredImage.PixelFormat.ToString()); Console.Write(sourceImage.PixelFormat.ToString()); filteredImage = ImageUtilities.convert(filteredImage, System.Drawing.Imaging.PixelFormat.Format32bppArgb); DA.SetData(0, filteredImage); }