public bool OverrideTextureMaps(string textureName, double reflection, double gloss, double specular) { if (Kn5 == null) { return(false); } if (_mapsBase == null) { Format format; var data = TextureReader.ToPng(DeviceContextHolder, Kn5.TexturesData[textureName], true, out format); _mapsBase = new MagickImage(data); if (_mapsBase.Width > 256 || _mapsBase.Height > 256) { _mapsBase.Resize(256, 256); } _mapsBase.AutoLevel(Channels.Red); _mapsBase.AutoLevel(Channels.Green); _mapsBase.AutoLevel(Channels.Blue); } using (var image = _mapsBase.Clone()) { image.Evaluate(Channels.Red, EvaluateOperator.Multiply, specular); image.Evaluate(Channels.Green, EvaluateOperator.Multiply, gloss); image.Evaluate(Channels.Blue, EvaluateOperator.Multiply, reflection); return(OverrideTexture(textureName, image.ToByteArray(MagickFormat.Png))); } }
public static MagickImage PerlinNoise(int width, int height) { using var noise1 = new MagickImage(MagickColors.Black, width / 160, height / 160); using var noise2 = new MagickImage(MagickColors.Black, width / 80, height / 80); using var noise3 = new MagickImage(MagickColors.Black, width / 40, height / 40); using var noise4 = new MagickImage(MagickColors.Black, width / 20, height / 20); using var noise5 = new MagickImage(MagickColors.Black, width / 10, height / 10); using var noise6 = new MagickImage(MagickColors.Black, width / 1, height / 1); noise1.AddNoise(NoiseType.Random); noise2.AddNoise(NoiseType.Random); noise3.AddNoise(NoiseType.Random); noise4.AddNoise(NoiseType.Random); noise5.AddNoise(NoiseType.Random); noise1.VirtualPixelMethod = VirtualPixelMethod.Tile; noise2.VirtualPixelMethod = VirtualPixelMethod.Tile; noise3.VirtualPixelMethod = VirtualPixelMethod.Tile; noise4.VirtualPixelMethod = VirtualPixelMethod.Tile; noise5.VirtualPixelMethod = VirtualPixelMethod.Tile; noise6.VirtualPixelMethod = VirtualPixelMethod.Tile; var geometry = new MagickGeometry(width, height) { FillArea = true }; noise1.Evaluate(Channels.Default, EvaluateOperator.Multiply, 0.5); noise1.Evaluate(Channels.Default, EvaluateOperator.Add, 0.25); noise1.Resize(geometry); noise2.Evaluate(Channels.Default, EvaluateOperator.Multiply, 0.25); noise2.Evaluate(Channels.Default, EvaluateOperator.Add, 0.375); noise2.Resize(geometry); noise3.Evaluate(Channels.Default, EvaluateOperator.Multiply, 0.125); noise3.Evaluate(Channels.Default, EvaluateOperator.Add, 0.4375); noise3.Resize(geometry); noise4.Evaluate(Channels.Default, EvaluateOperator.Multiply, 0.0625); noise4.Evaluate(Channels.Default, EvaluateOperator.Add, 0.46875); noise4.Resize(geometry); noise5.Evaluate(Channels.Default, EvaluateOperator.Multiply, 0.03125); noise5.Evaluate(Channels.Default, EvaluateOperator.Add, 0.484375); noise5.Resize(geometry); noise6.Evaluate(Channels.Default, EvaluateOperator.Multiply, 0.015625); noise6.Evaluate(Channels.Default, EvaluateOperator.Add, 0.49921875); noise6.Resize(geometry); noise1.Composite(noise2, CompositeOperator.Plus); noise1.Composite(noise3, CompositeOperator.Plus); noise1.Composite(noise4, CompositeOperator.Plus); noise1.Composite(noise5, CompositeOperator.Plus); noise1.Composite(noise6, CompositeOperator.Plus); noise1.AutoLevel(); return((MagickImage)noise1.Clone()); }
public override void Apply(MagickImage image) { using var noise = new MagickImage(MagickColors.Black, image.Width, image.Height); noise.AddNoise(NoiseType.Random); noise.VirtualPixelMethod = VirtualPixelMethod.Tile; noise.Blur(0, 5); noise.AutoLevel(); var green = noise.Separate(Channels.Green).First(); image.Composite(green, CompositeOperator.SrcOver); }
public static ComparisonResult Compare(IMagickImage original, IMagickImage updated) { var compareResult = new ComparisonResult(); // https://github.com/dlemstra/Magick.NET/blob/9943055423b90ac35933dde602b3af9aab746a8a/Source/Magick.NET/Shared/Enums/ErrorMetric.cs // https://www.imagemagick.org/script/command-line-options.php#metric var compareSettings = new CompareSettings() { HighlightColor = MagickColors.White,//MagickColor.FromRgba(255, 20, 147, 255), LowlightColor = MagickColors.Black, Metric = ErrorMetric.Absolute }; using (IMagickImage originalMImage = new MagickImage(original)) { // Set Fuzzing Level originalMImage.ColorFuzz = new Percentage(8); compareResult.TotalPixels = originalMImage.Height * originalMImage.Width; using (IMagickImage diffMImage = new MagickImage()) { using (IMagickImage updatedMImage = new MagickImage(updated)) { compareResult.ChangedPixels = originalMImage.Compare(updatedMImage, compareSettings, diffMImage); } // flatten the colors diffMImage.AutoLevel(); // bold the diff, make the changes pop diffMImage.Morphology(new MorphologySettings { Kernel = Kernel.Octagon, KernelArguments = "5", Method = MorphologyMethod.Dilate }); // flip the colors diffMImage.Opaque(MagickColors.White, MagickColors.Red); diffMImage.Opaque(MagickColors.Black, MagickColors.Transparent); using (var origFadeImg = new MagickImage(original)) { origFadeImg.Colorize(MagickColors.White, new Percentage(75)); using (IMagickImageCollection collection = new MagickImageCollection(origFadeImg.ToByteArray())) { collection.Add(diffMImage); compareResult.DiffImage = new MagickImage(collection.Merge()); } } } } return(compareResult); }
public static void AutoLevel(string path) { MagickImage img = IOUtils.ReadImage(path); if (img == null) { return; } string fname = Path.ChangeExtension(path, null); Print("-> " + fname + "\n"); img.AutoLevel(); img.Write(path); }
public async Task SaveTextureMaps(string filename, string baseTextureName, double reflection, double gloss, double specular) { if (Kn5 == null) { return; } MagickImage image = null; await Task.Run(() => { Format format; var data = TextureReader.ToPng(DeviceContextHolder, Kn5.TexturesData[baseTextureName], true, out format); image = new MagickImage(data); image.AutoLevel(Channels.Red); image.AutoLevel(Channels.Green); image.AutoLevel(Channels.Blue); image.Evaluate(Channels.Red, EvaluateOperator.Multiply, specular); image.Evaluate(Channels.Green, EvaluateOperator.Multiply, gloss); image.Evaluate(Channels.Blue, EvaluateOperator.Multiply, reflection); }); await SaveAndDispose(filename, image); }
private Bitmap DistortImage(Bitmap bitmap, IntPoint p1, IntPoint p2, IntPoint p3, IntPoint p4) { if (p1.X != 0 && p2.Y != 0 && p3.Y != 0 && p4.X != 0) { using (MagickImage image = new MagickImage(bitmap)) { if (cbNormalize.IsChecked ?? true) { image.Normalize(); } if (cbAutoGamma.IsChecked ?? true) { image.AutoGamma(); } if (cbAutoLevel.IsChecked ?? true) { image.AutoLevel(); } image.Threshold(new Percentage(int.Parse(tbThreshold.Text))); image.Distort(DistortMethod.Perspective, new double[] { p1.X, p1.Y, 0, 0, p2.X, p2.Y, image.Width, 0, p3.X, p3.Y, 0, image.Height, p4.X, p4.Y, image.Width, image.Height }); MagickGeometry size = new MagickGeometry(561, 795) { IgnoreAspectRatio = true }; image.Resize(size); //image.Write("C:\\Users\\RLabonde\\Desktop\\test\\test.bmp"); return(image.ToBitmap()); } } else { System.Windows.Forms.MessageBox.Show("No point was detected!", "No points", MessageBoxButtons.OK, MessageBoxIcon.Error); return(bitmap); } }
private static void RemoveLines(MagickImage original, MagickImage image, string geometryValue) { image.Scale(new MagickGeometry(geometryValue)); MagickGeometry geometry = new MagickGeometry(original.Width, original.Height); geometry.IgnoreAspectRatio = true; image.Scale(geometry); image.AutoLevel(); //image.Shave(20, 20); image.Despeckle(); image.ReduceNoise(); image.Morphology(MorphologyMethod.Erode, Kernel.Diamond, 2); using (MagickImage clone = (MagickImage)image.Clone()) { image.Negate(); image.Composite(original, Gravity.Center); } }
private static System.Drawing.Image EnchanceDPI(System.Drawing.Image DPIImage) { //Bitmap currentImage = new Bitmap(ImageDirectory); //Bitmap cleanImage = CleanText.Resize(currentImage, currentImage.Width, currentImage.Height); //using (MagickImage img = new MagickImage(cleanImage)) //{ // img.Write("ManualImage.tif"); //} // QuantizeSettings qs = new QuantizeSettings(); // qs.ColorSpace = ColorSpace.Gray; // image.Quantize(qs); //image.ColorType = ColorType.Grayscale; //image.ContrastStretch(new Percentage(0), new Percentage(0)); //QuantizeSettings qs2 = new QuantizeSettings(); //image.Negate(); //qs2.ColorSpace = ColorSpace.GRAY; //image.Quantize(qs2); //image.ColorType = ColorType.Grayscale; //image.AdaptiveThreshold(30, 30, 10); // image.BackgroundColor = Color.White; //image.AdaptiveThreshold(15, 15, 10); //image.ContrastStretch(0, 0); //ImageOptimizer optimizer = new ImageOptimizer(); //optimizer.LosslessCompress(image.FileName); // image.Negate(); MagickNET.Initialize(@"C:\OCR\File\"); // Read first frame of gif image using (MagickImage image = new MagickImage("Snakeware.gif")) { image.Density = new PointD(600, 600); image.AutoLevel(); image.Negate(); image.AdaptiveThreshold(30, 30, 10); image.Negate(); image.Write("Snakeware.jpg"); } // Write to stream MagickReadSettings settings = new MagickReadSettings(); // Tells the xc: reader the image to create should be 800x600 settings.Width = 800; settings.Height = 600; //settings.Density = 600; using (MemoryStream memStream = new MemoryStream()) { // Create image that is completely purple and 800x600 using (MagickImage image = new MagickImage("xc:purple", settings)) { // Sets the output format to png image.Format = MagickFormat.Png; // Write the image to the memorystream image.Write(memStream); } } return(DPIImage); }
private Bitmap processImgForScanning(Bitmap imgInput) { using (MemoryStream memstream = new MemoryStream()) { imgInput.Save(memstream, ImageFormat.Tiff); MagickImage img = new MagickImage(memstream.ToArray()); if (sharpen) { img.Sharpen((int)sharpenIntX.Value, (int)sharpenIntY.Value, Channels.All); } if (autoGamma) { img.AutoGamma(); } if (enhance) { img.Enhance(); } if (contrast) { img.Contrast(); } if (autoLevel) { img.AutoLevel(); } if (autoOrient) { img.AutoOrient(); } if (despeckle) { img.Despeckle(); } if (medianFilter) { img.MedianFilter((int)medianInt.Value); } if (unsharpmask) { img.Unsharpmask(6.8, 4, 4, 0); } if (wtThreshold) { img.LinearStretch((float)0.9, 0.1); //img.WhiteThreshold((int)wtThresInt.Value); //img.ReduceNoise(); //img.Grayscale(PixelIntensityMethod.Brightness); } if (invert) { img.Negate(); } return(img.ToBitmap()); } }
public override void Apply(MagickImage image) { image.AutoLevel(); }