Ejemplo n.º 1
0
 internal Item(ImageComparer imageComparer, bool reverse)
 {
     _resourceResolver = new ResourceResolver(imageComparer.GetType(), false);
     _description = imageComparer.Description;
     Name = imageComparer.Name;
     IsReverse = reverse;
     Comparer = imageComparer.GetComparer(reverse);
 }
 public void IsEqual(string src1, string src2, bool equal)
 {
     using (var s1 = Utils.Load(src1))
     using (var s2 = Utils.Load(src2))
     {
         var ic = new ImageComparer();
         Assert.AreEqual(equal, ic.IsEqual(s1,s2));
     }
 }        
        public void ZoneIsExtracted()
        {
            var original = Utils.Load("Zoning.OverallStatus_NoZones"); //article without cut zone
            var zoned = Utils.Load("Zoning.OverallStatus_Zoned"); //article with cut zone
           
            var extractor = new ZoneExtractor();

            var actual = extractor.ExtractZone(original, zoned);
            var expected = Utils.Load("Zoning.OverallStatus_ZoneCut"); //just the donkey

            var comparer = new ImageComparer();
            Assert.IsTrue(comparer.IsEqual(expected, actual));
        }
        public void ZoneExtractedIsWrong()
        {
            var original = Utils.Load("Zoning.OverallStatus_NoZones"); //article without cut zone
            var zoned = Utils.Load("Zoning.OverallStatus_Zoned"); //article with cut zone

            var extractor = new ZoneExtractor();

            var actual = extractor.ExtractZone(original, zoned);
            var expected = Utils.Load("Zoning.OverallStatus_ZoneCutIsCat"); //its the cat

            var comparer = new ImageComparer();
            Assert.IsFalse(comparer.IsEqual(expected, actual));
        }
Ejemplo n.º 5
0
        public void ImageShouldApplyBinaryThresholdInBox <TPixel>(TestImageProvider <TPixel> provider, float value)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            using (Image <TPixel> source = provider.GetImage())
                using (var image = source.Clone())
                {
                    var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2);

                    image.Mutate(x => x.BinaryThreshold(value, bounds));
                    image.DebugSave(provider, value);

                    ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds);
                }
        }
Ejemplo n.º 6
0
        public void ImageShouldApplyVignetteFilterInBox <TPixel>(TestImageProvider <TPixel> provider)
            where TPixel : struct, IPixel <TPixel>
        {
            using (Image <TPixel> source = provider.GetImage())
                using (var image = new Image <TPixel>(source))
                {
                    var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2);

                    image.Vignette(bounds)
                    .DebugSave(provider, null, Extensions.Bmp);

                    ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
                }
        }
Ejemplo n.º 7
0
        public void TolerantImageComparer_ApprovesSimilarityBelowTolerance <TPixel>(TestImageProvider <TPixel> provider)
            where TPixel : struct, IPixel <TPixel>
        {
            using (Image <TPixel> image = provider.GetImage())
            {
                using (Image <TPixel> clone = image.Clone())
                {
                    ImagingTestCaseUtility.ModifyPixel(clone, 0, 0, 1);

                    var comparer = ImageComparer.Tolerant();
                    comparer.VerifySimilarity(image, clone);
                }
            }
        }
Ejemplo n.º 8
0
        public void ApplyOilPaintFilterInBox <TPixel>(TestImageProvider <TPixel> provider, int levels, int brushSize)
            where TPixel : struct, IPixel <TPixel>
        {
            using (Image <TPixel> source = provider.GetImage())
                using (Image <TPixel> image = source.Clone())
                {
                    var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2);

                    image.Mutate(x => x.OilPaint(levels, brushSize, bounds));
                    image.DebugSave(provider, string.Join("-", levels, brushSize));

                    ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds);
                }
        }
Ejemplo n.º 9
0
        public void ImageShouldApplyBinaryThresholdInBox <TPixel>(TestImageProvider <TPixel> provider, float value)
            where TPixel : struct, IPixel <TPixel>
        {
            using (Image <TPixel> source = provider.GetImage())
                using (var image = new Image <TPixel>(source))
                {
                    var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2);

                    image.BinaryThreshold(value, bounds)
                    .DebugSave(provider, value, Extensions.Bmp);

                    ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
                }
        }
Ejemplo n.º 10
0
        public void ImageShouldApplyVignetteFilterInBox <TPixel>(TestImageProvider <TPixel> provider)
            where TPixel : struct, IPixel <TPixel>
        {
            using (Image <TPixel> source = provider.GetImage())
                using (var image = source.Clone())
                {
                    var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2);

                    image.Mutate(x => x.Vignette(bounds));
                    image.DebugSave(provider);

                    ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds);
                }
        }
Ejemplo n.º 11
0
        public static void RunValidatingProcessorTestOnWrappedMemoryImage <TPixel>(
            this TestImageProvider <TPixel> provider,
            Action <IImageProcessingContext> process,
            object testOutputDetails           = null,
            ImageComparer comparer             = null,
            string useReferenceOutputFrom      = null,
            bool appendPixelTypeToFileName     = true,
            bool appendSourceFileOrDescription = true)
            where TPixel : struct, IPixel <TPixel>
        {
            if (comparer == null)
            {
                comparer = ImageComparer.TolerantPercentage(0.001f);
            }

            using (Image <TPixel> image0 = provider.GetImage())
            {
                var mmg = TestMemoryManager <TPixel> .CreateAsCopyOf(image0.GetPixelSpan());

                using (var image1 = Image.WrapMemory(mmg.Memory, image0.Width, image0.Height))
                {
                    image1.Mutate(process);
                    image1.DebugSave(
                        provider,
                        testOutputDetails,
                        appendPixelTypeToFileName: appendPixelTypeToFileName,
                        appendSourceFileOrDescription: appendSourceFileOrDescription);

                    // TODO: Investigate the cause of pixel inaccuracies under Linux
                    if (TestEnvironment.IsWindows)
                    {
                        string testNameBackup = provider.Utility.TestName;

                        if (useReferenceOutputFrom != null)
                        {
                            provider.Utility.TestName = useReferenceOutputFrom;
                        }

                        image1.CompareToReferenceOutput(
                            comparer,
                            provider,
                            testOutputDetails,
                            appendPixelTypeToFileName: appendPixelTypeToFileName,
                            appendSourceFileOrDescription: appendSourceFileOrDescription);

                        provider.Utility.TestName = testNameBackup;
                    }
                }
            }
        }
Ejemplo n.º 12
0
        public void ApplyDitherFilterInBox <TPixel>(TestImageProvider <TPixel> provider)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            using (Image <TPixel> source = provider.GetImage())
                using (Image <TPixel> image = source.Clone())
                {
                    var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2);

                    image.Mutate(x => x.BinaryDither(DefaultDitherer, bounds));
                    image.DebugSave(provider);

                    ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds);
                }
        }
Ejemplo n.º 13
0
        static void Main(string[] args)
        {
            ChromeDriver driver = new ChromeDriver();


            driver.Navigate().GoToUrl("https://passport.cnblogs.com/user/signin");
            driver.Manage().Window.Maximize();//窗口最大化,便于脚本执行

            //设置超时等待(隐式等待)时间设置10秒
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10000);

            driver.FindElementByXPath("//*[@id=\"input1\"]").SendKeys("username");

            driver.FindElementByXPath("//*[@id=\"input2\"]").SendKeys("password");

            driver.FindElementByXPath("//*[@id=\"signin\"]").Click();
            Thread.Sleep(3000);
            driver.FindElementByXPath("//*[@id=\"captchaBox\"]/div/div[2]/div[1]/div[3]/span[1]").Click();
            Actions actions = new Actions(driver);

            Thread.Sleep(3000);
            driver.GetScreenshot().SaveAsFile("原始验证图.png");
            // /html/body/div[3]/div[2]/div[1]/div/div[1]/div[2]/div[2]
            driver.FindElementByXPath("/html/body/div[3]/div[2]/div[1]/div/div[1]/div[2]/div[2]").Click();
            //actions.DragAndDropToOffset(driver,leftShift,0).Build().Perform();//单击并在指定的元素上按下鼠标按钮,然后移动到指定位置
            Thread.Sleep(3000);
            driver.GetScreenshot().SaveAsFile("阴影验证图.png");

            //E:\LoginTest-master\LoginTest-master\LoginTest\bin\Debug
            Bitmap a = new Bitmap(@"E:\LoginTest-master\LoginTest-master\LoginTest\bin\Debug\原始验证图.png");
            Bitmap b = new Bitmap(@"E:\LoginTest-master\LoginTest-master\LoginTest\bin\Debug\阴影验证图.png");
            int    c = GetArgb(a, b);

            actions.DragAndDropToOffset(driver.FindElementByXPath("/html/body/div[3]/div[2]/div[1]/div/div[1]/div[2]/div[2]"), c - 494, 0).Build().Perform();//移动滑块到阴影处


            List <Rectangle> Compare = ImageComparer.Compare(a, b);

            foreach (Rectangle item in Compare)
            {
                Thread.Sleep(2000);
                actions.DragAndDropToOffset(driver.FindElementByXPath("/html/body/div[3]/div[2]/div[1]/div/div[1]/div[2]/div[2]"), item.X + 13, 0).Build().Perform();   //移动滑块到阴影处
            }

            while (true)
            {
                Thread.Sleep(1000);
                Console.WriteLine(0);
            }
        }
Ejemplo n.º 14
0
        public void ImageShouldApplyColorBlindnessFilterInBox <TPixel>(TestImageProvider <TPixel> provider, ColorBlindness colorBlindness)
            where TPixel : struct, IPixel <TPixel>
        {
            using (Image <TPixel> source = provider.GetImage())
                using (var image = new Image <TPixel>(source))
                {
                    var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2);

                    image.ColorBlindness(colorBlindness, bounds)
                    .DebugSave(provider, colorBlindness.ToString(), Extensions.Bmp);

                    ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
                }
        }
Ejemplo n.º 15
0
        public void DecodeProgressiveJpeg_PdfJs <TPixel>(TestImageProvider <TPixel> provider)
            where TPixel : struct, IPixel <TPixel>
        {
            using (Image <TPixel> image = provider.GetImage(PdfJsJpegDecoder))
            {
                image.DebugSave(provider);

                provider.Utility.TestName = DecodeProgressiveJpegOutputName;
                image.CompareToReferenceOutput(
                    provider,
                    ImageComparer.Tolerant(ProgressiveTolerance_PdfJs),
                    appendPixelTypeToFileName: false);
            }
        }
Ejemplo n.º 16
0
        public void ImageShouldApplyDiffusionFilterInBox <TPixel>(TestImageProvider <TPixel> provider, string name, IErrorDiffuser diffuser)
            where TPixel : struct, IPixel <TPixel>
        {
            using (Image <TPixel> source = provider.GetImage())
                using (var image = new Image <TPixel>(source))
                {
                    var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2);

                    image.Dither(diffuser, .5F, bounds)
                    .DebugSave(provider, name, Extensions.Bmp);

                    ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
                }
        }
        public void TolerantComparer_CompareImages_CheckerImage()
        {
            var perPixelManhattanThresholdValue = ImageComparer.CalculatePerPixelManhattanThresholdValue(3, ImageComparer.DefaultPerPixelChannelManhattanThreshold);
            var reports = ImageComparer.Tolerant(0, perPixelManhattanThresholdValue).CompareImages(BaseImage, CheckerChangeImage).ToArray();

            Assert.Single(reports);
            using var actualDifference = reports[0].CreateDifferenceImage();
            var ExpectedDifferencePath = Path.Combine(PathHelper.ImagesPath, "ExpectedDifference.png");

            using var expectedDifference = Image.Load <Rgba32>(ExpectedDifferencePath);
            var differenceReports = ImageComparer.Exact().CompareImages(expectedDifference, actualDifference).ToArray();

            Assert.Empty(differenceReports);
        }
Ejemplo n.º 18
0
        private void ExecuteCheck()
        {
            if (ImageList.Count > 1)
            {
                double totalCompareCount = (ImageList.Count * (ImageList.Count - 1)) / 2;
                double completeCount     = 0.0;

                Enabled = false;

                foreach (var source in ImageList)
                {
                    foreach (var target in ImageList.Where(x => x.No != source.No && x.Checked == false))
                    {
                        var comparer = new ImageComparer();

                        comparer.Source = source;
                        source.Checked  = true;

                        comparer.Target = target;
                        var similarity = comparer.CalculateSimilarity();

                        if (similarity > 0.9)
                        {
                            var window = new SelectWindow();
                            var vm     = window.DataContext as SelectWindowViewModel;

                            if (vm.IsNotNull())
                            {
                                vm.Pic1       = source;
                                vm.Pic2       = target;
                                vm.Similarity = (int)((System.Math.Round(similarity, 2)) * 100);
                                window.ShowDialog();
                                window.DataContext = null;
                            }
                        }

                        comparer.Dispose();

                        _uiTaskHelper.ChangeByDispatcher(() =>
                        {
                            ProgressValue = (int)((System.Math.Round(++completeCount / totalCompareCount, 2)) * 100);
                        });
                    }
                }

                ShowMessageOkOnly("결과메시지", "중복 이미지 검색을 마쳤습니다.");
                Enabled = true;
            }
        }
Ejemplo n.º 19
0
        public void BmpDecoder_CanDecodeBitfields_WithUnusualBitmasks <TPixel>(TestImageProvider <TPixel> provider)
            where TPixel : struct, IPixel <TPixel>
        {
            using (Image <TPixel> image = provider.GetImage(new BmpDecoder()))
            {
                image.DebugSave(provider);

                // Choosing large tolerance of 6.1 here, because for some reason with the MagickReferenceDecoder the alpha channel
                // seems to be wrong. This bitmap has an alpha channel of two bits. In many cases this alpha channel has a value of 3,
                // which should be remapped to 255 for RGBA32, but the magick decoder has a value of 191 set.
                // The total difference without the alpha channel is still: 0.0204%
                // Exporting the image as PNG with GIMP yields to the same result as the imagesharp implementation.
                image.CompareToOriginal(provider, ImageComparer.TolerantPercentage(6.1f), new MagickReferenceDecoder());
            }
        }
 /// <summary>
 /// Compares the image against the expected Reference output, throws an exception if the images are not similar enough.
 /// The output file should be named identically to the output produced by <see cref="DebugSave{TPixel}(Image{TPixel}, ITestImageProvider, object, string, bool)"/>.
 /// </summary>
 /// <typeparam name="TPixel">The pixel format.</typeparam>
 /// <param name="image">The image which should be compared to the reference image.</param>
 /// <param name="provider">The image provider.</param>
 /// <param name="testOutputDetails">Details to be concatenated to the test output file, describing the parameters of the test.</param>
 /// <param name="extension">The extension</param>
 /// <param name="appendPixelTypeToFileName">A boolean indicating whether to append the pixel type to the  output file name.</param>
 /// <param name="appendSourceFileOrDescription">A boolean indicating whether to append <see cref="ITestTextureProvider.SourceFileOrDescription"/> to the test output file name.</param>
 /// <returns>The image.</returns>
 public static Image <TPixel> CompareToReferenceOutput <TPixel>(
     this Image <TPixel> image,
     ITestTextureProvider provider,
     object testOutputDetails           = null,
     string extension                   = "png",
     bool appendPixelTypeToFileName     = false,
     bool appendSourceFileOrDescription = false)
     where TPixel : unmanaged, IPixel <TPixel> => CompareToReferenceOutput(
     image,
     ImageComparer.Tolerant(),
     provider,
     testOutputDetails,
     extension,
     appendPixelTypeToFileName,
     appendSourceFileOrDescription);
Ejemplo n.º 21
0
 /// <summary>
 /// Utility method for doing the following in one step:
 /// 1. Executing an operation (taken as a delegate)
 /// 2. Executing DebugSave()
 /// 3. Executing CompareToReferenceOutput()
 /// </summary>
 internal static void VerifyOperation <TPixel>(
     this TestImageProvider <TPixel> provider,
     Action <Image <TPixel> > operation,
     FormattableString testOutputDetails,
     bool appendPixelTypeToFileName     = true,
     bool appendSourceFileOrDescription = true)
     where TPixel : unmanaged, IPixel <TPixel>
 {
     provider.VerifyOperation(
         ImageComparer.Tolerant(),
         operation,
         testOutputDetails,
         appendPixelTypeToFileName,
         appendSourceFileOrDescription);
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Utility method for doing the following in one step:
 /// 1. Executing an operation (taken as a delegate)
 /// 2. Executing DebugSave()
 /// 3. Executing CompareToReferenceOutput()
 /// </summary>
 internal static void VerifyOperation <TPixel>(
     this TestImageProvider <TPixel> provider,
     ImageComparer comparer,
     Action <Image <TPixel> > operation,
     bool appendPixelTypeToFileName     = true,
     bool appendSourceFileOrDescription = true)
     where TPixel : unmanaged, IPixel <TPixel>
 {
     provider.VerifyOperation(
         comparer,
         operation,
         $"",
         appendPixelTypeToFileName,
         appendSourceFileOrDescription);
 }
 public static Image <TPixel> CompareToReferenceOutput <TPixel>(
     this Image <TPixel> image,
     ImageComparer comparer,
     ITestImageProvider provider,
     FormattableString testOutputDetails,
     string extension = "png",
     bool grayscale   = false,
     bool appendPixelTypeToFileName = true)
     where TPixel : unmanaged, IPixel <TPixel> => image.CompareToReferenceOutput(
     comparer,
     provider,
     (object)testOutputDetails,
     extension,
     grayscale,
     appendPixelTypeToFileName);
Ejemplo n.º 24
0
 public void TolerantImageComparer_ApprovesPerfectSimilarity <TPixel>(
     TestImageProvider <TPixel> provider,
     float imageTheshold,
     int pixelThreshold)
     where TPixel : struct, IPixel <TPixel>
 {
     using (Image <TPixel> image = provider.GetImage())
     {
         using (Image <TPixel> clone = image.Clone())
         {
             var comparer = ImageComparer.Tolerant(imageTheshold, pixelThreshold);
             comparer.VerifySimilarity(image, clone);
         }
     }
 }
 public static Image <TPixel> CompareFirstFrameToReferenceOutput <TPixel>(
     this Image <TPixel> image,
     ImageComparer comparer,
     ITestImageProvider provider,
     FormattableString testOutputDetails,
     string extension = "png",
     bool appendPixelTypeToFileName     = true,
     bool appendSourceFileOrDescription = true)
     where TPixel : unmanaged, IPixel <TPixel> => image.CompareFirstFrameToReferenceOutput(
     comparer,
     provider,
     (object)testOutputDetails,
     extension,
     appendPixelTypeToFileName,
     appendSourceFileOrDescription);
Ejemplo n.º 26
0
 /// <summary>
 /// Same as <see cref="RunValidatingProcessorTest{TPixel}"/> but with an additional <see cref="Rectangle"/> parameter passed to 'process'
 /// </summary>
 internal static void RunRectangleConstrainedValidatingProcessorTest <TPixel>(
     this TestImageProvider <TPixel> provider,
     Action <IImageProcessingContext <TPixel>, Rectangle> process,
     object testOutputDetails = null,
     ImageComparer comparer   = null)
     where TPixel : struct, IPixel <TPixel>
 {
     using (Image <TPixel> image = provider.GetImage())
     {
         var bounds = new Rectangle(image.Width / 4, image.Width / 4, image.Width / 2, image.Height / 2);
         image.Mutate(x => process(x, bounds));
         image.DebugSave(provider, testOutputDetails);
         image.CompareToReferenceOutput(provider, testOutputDetails);
     }
 }
Ejemplo n.º 27
0
        private static void TestPngEncoderCore <TPixel>(
            TestImageProvider <TPixel> provider,
            PngColorType pngColorType,
            int compressionLevel        = 6,
            int paletteSize             = 0,
            bool appendPngColorType     = false,
            bool appendPixelType        = false,
            bool appendCompressionLevel = false,
            bool appendPaletteSize      = false)
            where TPixel : struct, IPixel <TPixel>
        {
            using (Image <TPixel> image = provider.GetImage())
            {
                if (!HasAlpha(pngColorType))
                {
                    image.Mutate(c => c.MakeOpaque());
                }

                var encoder = new PngEncoder
                {
                    PngColorType     = pngColorType,
                    CompressionLevel = compressionLevel,
                    PaletteSize      = paletteSize
                };

                string pngColorTypeInfo     = appendPngColorType ? pngColorType.ToString() : "";
                string compressionLevelInfo = appendCompressionLevel ? $"_C{compressionLevel}" : "";
                string paletteSizeInfo      = appendPaletteSize ? $"_PaletteSize-{paletteSize}" : "";
                string debugInfo            = $"{pngColorTypeInfo}{compressionLevelInfo}{paletteSizeInfo}";
                //string referenceInfo = $"{pngColorTypeInfo}";

                // Does DebugSave & load reference CompareToReferenceInput():
                string actualOutputFile = ((ITestImageProvider)provider).Utility.SaveTestOutputFile(image, "png", encoder, debugInfo, appendPixelType);

                IImageDecoder referenceDecoder    = TestEnvironment.GetReferenceDecoder(actualOutputFile);
                string        referenceOutputFile = ((ITestImageProvider)provider).Utility.GetReferenceOutputFileName("png", debugInfo, appendPixelType);

                using (var actualImage = Image.Load <TPixel>(actualOutputFile, referenceDecoder))
                    using (var referenceImage = Image.Load <TPixel>(referenceOutputFile, referenceDecoder))
                    {
                        ImageComparer comparer = pngColorType == PngColorType.Palette
                                                 ? ImageComparer.Tolerant(ToleranceThresholdForPaletteEncoder)
                                                 : ImageComparer.Exact;

                        comparer.VerifySimilarity(referenceImage, actualImage);
                    }
            }
        }
Ejemplo n.º 28
0
        public void TolerantImageComparer_TestPerPixelThreshold <TPixel>(TestImageProvider <TPixel> provider)
            where TPixel : struct, IPixel <TPixel>
        {
            using (Image <TPixel> image = provider.GetImage())
            {
                using (Image <TPixel> clone = image.Clone())
                {
                    ImagingTestCaseUtility.ModifyPixel(clone, 0, 0, 10);
                    ImagingTestCaseUtility.ModifyPixel(clone, 1, 0, 10);
                    ImagingTestCaseUtility.ModifyPixel(clone, 2, 0, 10);

                    var comparer = ImageComparer.Tolerant(perPixelManhattanThreshold: 42);
                    comparer.VerifySimilarity(image, clone);
                }
            }
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Compares 2 images and return the difference expressed as a percentage
        /// </summary>
        /// <param name="source1">Image 1</param>
        /// <param name="source2">Image 2</param>
        /// <param name="fuzzines">Image 2</param>
        /// <returns>float value that indicates the difference expressed as percentage</returns>
        public string ImagesMatchReturnValue(Image source1, Image source2, int fuzzines = -1)
        {
            byte fuz;

            if (fuzzines == -1)
            {
                fuz = Config.Settings.imageCompareSettings.fuzziness;
            }
            else
            {
                fuz = Byte.Parse(fuzzines.ToString());
            }
            difference       = ImageComparer.ImageComparePercentage(source1, source2, fuz);
            differenceString = (difference * 100).ToString("0.##");
            return(differenceString);
        }
Ejemplo n.º 30
0
        public void DetectEdges2D_WorksWithAllFilters <TPixel>(
            TestImageProvider <TPixel> provider,
            EdgeDetector2DKernel detector,
            string name)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            bool          hasAlpha = provider.SourceFileOrDescription.Contains("TestPattern");
            ImageComparer comparer = hasAlpha ? TransparentComparer : OpaqueComparer;

            using (Image <TPixel> image = provider.GetImage())
            {
                image.Mutate(x => x.DetectEdges(detector));
                image.DebugSave(provider, name);
                image.CompareToReferenceOutput(comparer, provider, name);
            }
        }
Ejemplo n.º 31
0
        public void WorkingBufferSizeHintInBytes_IsAppliedCorrectly <TPixel>(
            TestImageProvider <TPixel> provider,
            int workingBufferLimitInRows)
            where TPixel : struct, IPixel <TPixel>
        {
            using (Image <TPixel> image0 = provider.GetImage())
            {
                Size destSize = image0.Size() / 4;

                var configuration = Configuration.CreateDefaultInstance();

                int workingBufferSizeHintInBytes = workingBufferLimitInRows * destSize.Width * SizeOfVector4;
                var allocator = new TestMemoryAllocator();
                configuration.MemoryAllocator = allocator;
                configuration.WorkingBufferSizeHintInBytes = workingBufferSizeHintInBytes;

                var verticalKernelMap = ResizeKernelMap.Calculate(
                    KnownResamplers.Bicubic,
                    destSize.Height,
                    image0.Height,
                    Configuration.Default.MemoryAllocator);
                int minimumWorkerAllocationInBytes = verticalKernelMap.MaxDiameter * 2 * destSize.Width * SizeOfVector4;
                verticalKernelMap.Dispose();

                using (Image <TPixel> image = image0.Clone(configuration))
                {
                    image.Mutate(x => x.Resize(destSize, KnownResamplers.Bicubic, false));

                    image.DebugSave(
                        provider,
                        testOutputDetails: workingBufferLimitInRows,
                        appendPixelTypeToFileName: false);
                    image.CompareToReferenceOutput(
                        ImageComparer.TolerantPercentage(0.001f),
                        provider,
                        testOutputDetails: workingBufferLimitInRows,
                        appendPixelTypeToFileName: false);

                    Assert.NotEmpty(allocator.AllocationLog);

                    int maxAllocationSize = allocator.AllocationLog.Where(
                        e => e.ElementType == typeof(Vector4)).Max(e => e.LengthInBytes);

                    Assert.True(maxAllocationSize <= Math.Max(workingBufferSizeHintInBytes, minimumWorkerAllocationInBytes));
                }
            }
        }
Ejemplo n.º 32
0
        public void From24bppRgbSystemDrawingBitmap <TPixel>(TestImageProvider <TPixel> provider)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            string path = SavePng(provider, PngColorType.Rgb);

            using (Image <TPixel> original = provider.GetImage())
            {
                using (var sdBitmap = new System.Drawing.Bitmap(path))
                {
                    using (Image <TPixel> resaved = SystemDrawingBridge.From24bppRgbSystemDrawingBitmap <TPixel>(sdBitmap))
                    {
                        ImageComparer comparer = ImageComparer.Exact;
                        comparer.VerifySimilarity(original, resaved);
                    }
                }
            }
        }
Ejemplo n.º 33
0
 public static IEnumerable <ImageSimilarityReport> GetReferenceOutputSimilarityReports <TPixel>(
     this Image <TPixel> image,
     ITestImageProvider provider,
     ImageComparer comparer,
     object testOutputDetails       = null,
     string extension               = "png",
     bool appendPixelTypeToFileName = true)
     where TPixel : unmanaged, IPixel <TPixel>
 {
     using (Image <TPixel> referenceImage = provider.GetReferenceOutputImage <TPixel>(
                testOutputDetails,
                extension,
                appendPixelTypeToFileName))
     {
         return(comparer.CompareImages(referenceImage, image));
     }
 }
Ejemplo n.º 34
0
 public void VerifySimilarity_ThrowsOnSizeMismatch <TPixel>(TestImageProvider <TPixel> provider, int w, int h)
     where TPixel : struct, IPixel <TPixel>
 {
     using (Image <TPixel> image = provider.GetImage())
     {
         using (Image <TPixel> clone = image.Clone(ctx => ctx.Resize(w, h)))
         {
             ImageDimensionsMismatchException ex = Assert.ThrowsAny <ImageDimensionsMismatchException>(
                 () =>
             {
                 ImageComparer comparer = Mock.Of <ImageComparer>();
                 comparer.VerifySimilarity(image, clone);
             });
             this.Output.WriteLine(ex.Message);
         }
     }
 }
Ejemplo n.º 35
0
 internal Item(ImageComparer imageComparer, bool reverse)
 {
     _resourceResolver = new ResourceResolver(imageComparer.GetType(), false);
     _description = imageComparer.Description;
     Name = imageComparer.Name;
     IsReverse = reverse;
     _realDescription = !IsReverse
                            ? _resourceResolver.LocalizeString(_description)
                            : string.Format(SR.FormatSortByReverse, _resourceResolver.LocalizeString(_description));
     
     Comparer = imageComparer.GetComparer(reverse);
 }