public string Execute(FileItem item, string infile, string dest, ValuePairEnumerator configData) { var conf = new EnhanceViewModel(configData); dest = Path.Combine(Path.GetDirectoryName(dest), Path.GetFileNameWithoutExtension(dest) + ".jpg"); using (MagickImage image = new MagickImage(infile)) { if (conf.Normalize) image.Normalize(); if (conf.AutoGamma) image.AutoGamma(); image.BrightnessContrast(new Percentage(conf.Brightness), new Percentage(conf.Contrast)); if (conf.SContrast > 0) image.SigmoidalContrast(true, conf.SContrast); if (conf.Edge) image.AdaptiveSharpen(); if (conf.Sharpen > 0) image.UnsharpMask(1.5, 1.5, conf.Sharpen/100.0, 0.2); image.Format = MagickFormat.Jpeg; image.Write(dest); } return dest; }
private void ExecuteAutoGamma(XmlElement element, MagickImage image) { Hashtable arguments = new Hashtable(); foreach (XmlAttribute attribute in element.Attributes) { arguments[attribute.Name] = Variables.GetValue<Channels>(attribute); } if (arguments.Count == 0) image.AutoGamma(); else if (OnlyContains(arguments, "channels")) image.AutoGamma((Channels)arguments["channels"]); else throw new ArgumentException("Invalid argument combination for 'autoGamma', allowed combinations are: [] [channels]"); }
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 void Test_AutoGamma() { using (MagickImage image = new MagickImage(Files.Builtin.Logo)) { image.AutoGamma(); ColorAssert.AreEqual(new MagickColor("#00000003017E"), image, 496, 429); } }