public void Test_Execute_Null() { ExceptionAssert.ThrowsArgumentException <ArgumentNullException>(() => { var script = new AutotrimScript(); script.Execute(null); }, "input"); }
public void Execute_InputNull_ThrowsException() { ExceptionAssert.ThrowsArgumentException <ArgumentNullException>("input", () => { var script = new AutotrimScript(); script.Execute(null); }); }
private static void Test_Defaults(AutotrimScript script) { Assert.AreEqual(0, script.BorderColorLocation.X); Assert.AreEqual(0, script.BorderColorLocation.Y); Assert.AreEqual((Percentage)0, script.ColorFuzz); Assert.AreEqual(false, script.InnerTrim); Assert.AreEqual(0, script.PixelShift.Left); Assert.AreEqual(0, script.PixelShift.Top); Assert.AreEqual(0, script.PixelShift.Right); Assert.AreEqual(0, script.PixelShift.Bottom); }
private void Test_Execute(string input, Action <AutotrimScript> action, string output) { string inputFile = GetInputFile(input); using (var image = new MagickImage(inputFile)) { var script = new AutotrimScript(); action(script); var scriptOutput = script.Execute(image); TestOutput(scriptOutput, output); } }
public void Execute_logo_png() { using (var image = new MagickImage(Images.Logo)) { var script = new AutotrimScript(); script.InnerTrim = true; using (var scriptOutput = script.Execute(image)) { AssertOutput(scriptOutput, "logo.png"); } } }
public void BorderColorLocation_AfterBottomRight_ThrowsException() { var script = new AutotrimScript(); using (var logo = new MagickImage(Images.Logo)) { script.BorderColorLocation = new PointD(logo.Width, logo.Height); // TODO: Fix this after the next release of Magick.NET // ExceptionAssert.ThrowsArgumentException<ArgumentOutOfRangeException>("x", "Invalid X coordinate: " + logo.Width, () => ExceptionAssert.Throws <ArgumentOutOfRangeException>(() => { script.Execute(logo); }); } }
public void BorderColorLocation_BeforeLeftTop_ThrowsException() { var script = new AutotrimScript(); using (var logo = new MagickImage(Images.Logo)) { script.BorderColorLocation = new PointD(-1, -1); // TODO: Fix this after the next release of Magick.NET // ExceptionAssert.ThrowsArgumentException<ArgumentOutOfRangeException>("x", "Invalid X coordinate: -1", () => ExceptionAssert.Throws <ArgumentOutOfRangeException>(() => { script.Execute(logo); }); } }
public void Reset_AllSettingsChanged_RestoredToDefault() { var script = new AutotrimScript(); script.BorderColorLocation = new PointD(10, 10); script.ColorFuzz = (Percentage)6; script.InnerTrim = true; script.PixelShift.Left = 5; script.PixelShift.Top = 4; script.PixelShift.Right = 3; script.PixelShift.Bottom = 2; script.Reset(); AssertDefaults(script); }
public void Test_Defaults() { var script = new AutotrimScript(); Test_Defaults(script); script.BorderColorLocation = new PointD(10, 10); script.ColorFuzz = (Percentage)6; script.InnerTrim = true; script.PixelShift.Left = 5; script.PixelShift.Top = 4; script.PixelShift.Right = 3; script.PixelShift.Bottom = 2; script.Reset(); Test_Defaults(script); }
private void AssertExecuteWithFilename(string input, string output, Action <AutotrimScript> action) { string inputFile = GetInputFile(input); /* LosslessCompress(inputFile); */ using (var image = new MagickImage(inputFile)) { var script = new AutotrimScript(); action(script); using (var scriptOutput = script.Execute(image)) { AssertOutput(scriptOutput, output); } } }
public void Test_Settings() { var script = new AutotrimScript(); using (var logo = new MagickImage(Images.Logo)) { ExceptionAssert.Throws <ArgumentException>(() => { script.BorderColorLocation = new PointD(-1, -1); script.Execute(logo); }); ExceptionAssert.Throws <ArgumentException>(() => { script.BorderColorLocation = new PointD(logo.Width, logo.Height); script.Execute(logo); }); } }
public static void EnhanceImageQuality(string ImageDirectory) { // do image Enhance then call Do OCR // convert - density 600 input.pdf output.tif; //System.Drawing.Image SelectedImage = new System.Drawing.Image(); DirectoryInfo EnhancedImageDir = new DirectoryInfo(@"C:\OCR\EnhancedImage\"); Bitmap orgimg = (Bitmap)Bitmap.FromFile(ImageDirectory); Bitmap bitmap = (Bitmap)Bitmap.FromFile(ImageDirectory); Bitmap image2 = Grayscale.CommonAlgorithms.BT709.Apply(bitmap); Rectangle rec = new Rectangle(0, 0, bitmap.Width, bitmap.Height); BitmapData bitmapdata = bitmap.LockBits(rec, ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed); // create instance of skew checker DocumentSkewChecker skewChecker = new DocumentSkewChecker(); // get documents skew angle double angle = skewChecker.GetSkewAngle(bitmapdata); // create rotation filter RotateBilinear rotationFilter = new RotateBilinear(-angle); rotationFilter.FillColor = Color.White; // rotate image applying the filter bitmap.UnlockBits(bitmapdata); Bitmap rotatedImage = rotationFilter.Apply(orgimg); rotatedImage.Save(ImageDirectory + ".tif"); using (MagickImage image = new MagickImage(ImageDirectory)) { TextCleanerScript Cleaner = new TextCleanerScript(); // Cleaner.FilterSize = 12; // filter to clean up background; // Cleaner.FilterOffset = (Percentage)3; //filter in percent to reduce noise // Cleaner.Saturation = (Percentage)200; // high value to Saturation //// Cleaner.Unrotate = true; // var newImage1 = Cleaner.Execute(image); // //newImage1.CannyEdge(); selcet the inner objects in the image // newImage1.Density = new PointD(600, 600); // newImage1.Write(EnhancedImageDir + Path.GetFileName(ImageDirectory) // + ".tif"); AutotrimScript WhiteB = new AutotrimScript(); // WhiteB.InnerTrim = true; var a = WhiteB.GetLargestAreaP(image); WhiteboardScript AoutoTrim = new WhiteboardScript(); //AoutoTrim.SetCoordinates(new Coordinate(01, 53), new Coordinate(313, 31), //new Coordinate(331, 218), new Coordinate(218, 200)); //AoutoTrim.Enhance = WhiteboardEnhancements.Both; //AoutoTrim.FilterSize = 25; // filter to clean up background; //AoutoTrim.FilterOffset = (Percentage)3; //filter in percent to reduce noise //AoutoTrim.Saturation = (Percentage)200; // high value to Saturation //AoutoTrim.SetCoordinates(new Coordinate(a[0].X, a[0].Y), new Coordinate(a[1].X, a[1].Y), //new Coordinate(a[2].X, a[2].Y), new Coordinate(a[3].X, a[3].Y)); var new2mage2 = AoutoTrim.Execute(image); // new2mage2.Deskew((Percentage)2); AoutoTrim.SetCoordinates(new Coordinate(13, 3), new Coordinate(342, 6), new Coordinate(331, 467), new Coordinate(38, 482)); AoutoTrim.Enhance = WhiteboardEnhancements.Both; // new2mage2.Density= new PointD(300, 300); new2mage2 = WhiteB.Execute(new2mage2); new2mage2 = Cleaner.Execute(new2mage2); new2mage2.Density = new PointD(600, 600); new2mage2.Write(EnhancedImageDir + Path.GetFileName(ImageDirectory) + "2" + ".tif"); string dir12 = (EnhancedImageDir + Path.GetFileName(ImageDirectory) + "2" + ".tif"); Bitmap imageTobeDeske = new Bitmap(dir12); gmseDeskew deskew = new gmseDeskew(); deskew.New(imageTobeDeske); double angel = deskew.GetSkewAngle(); if (angel > 0) { angel = angel * -1; } WhiteB.BorderColorLocation = new Coordinate(10, 10); //AoutoTrim.SetCoordinates(ad); //WhiteB.ColorFuzz = (Percentage)20; //var new2mage3 = WhiteB.Execute(image); //new2mage3 = Cleaner.Execute(new2mage3); //new2mage3.Write(EnhancedImageDir + Path.GetFileName(ImageDirectory) // + "3" + ".tif"); } }
public void Constructor_SettingsSetToDefaults() { var script = new AutotrimScript(); AssertDefaults(script); }