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); }
public void ShouldAdjustTheImage() { using (var image = new MagickImage(Files.Builtin.Logo)) { image.AutoGamma(); ColorAssert.Equal(new MagickColor("#00000003017E"), image, 496, 429); } }
public void ShouldUseTheCorrectDefaultChannel() { using (var imageA = new MagickImage(Files.MagickNETIconPNG)) { using (var imageB = imageA.Clone()) { imageA.AutoGamma(); imageB.AutoGamma(Channels.Composite); var distortion = imageA.Compare(imageB, ErrorMetric.RootMeanSquared); Assert.Equal(0.0, distortion); } } }
public static void AutoGamma(string path) { MagickImage img = IOUtils.ReadImage(path); if (img == null) { return; } string fname = Path.ChangeExtension(path, null); Print("-> " + fname + "\n"); img.AutoGamma(); img.Write(path); }
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 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()); } }