AssertImagesAreIdentical() public static method

Asserts that two images are identical
public static AssertImagesAreIdentical ( Image expected, Image tested, string because ) : void
expected System.Drawing.Image /// The expected result ///
tested System.Drawing.Image /// The tested image ///
because string /// The because message. ///
return void
        public void EdgeDetectionEffectIsApplied()
        {
            foreach (ImageFactory imageFactory in this.ListInputImages())
            {
                Image original = (Image)imageFactory.Image.Clone();

                List <IEdgeFilter> filters = new List <IEdgeFilter>
                {
                    new KayyaliEdgeFilter(),
                    new KirschEdgeFilter(),
                    new Laplacian3X3EdgeFilter(),
                    new Laplacian5X5EdgeFilter(),
                    new LaplacianOfGaussianEdgeFilter(),
                    new PrewittEdgeFilter(),
                    new RobertsCrossEdgeFilter(),
                    new ScharrEdgeFilter(),
                    new SobelEdgeFilter()
                };

                foreach (IEdgeFilter filter in filters)
                {
                    imageFactory.DetectEdges(filter);
                    AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the edge operation should have been applied on {0}", imageFactory.ImagePath);
                    imageFactory.Reset();
                    AssertionHelpers.AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset");
                }
            }
        }
        public void AlphaIsModified()
        {
            foreach (ImageFactory imageFactory in this.ListInputImages())
            {
                Image original = (Image)imageFactory.Image.Clone();
                imageFactory.Alpha(50);

                ISupportedImageFormat format = imageFactory.CurrentImageFormat;

                // The Image class does not support alpha transparency in bitmaps.
                if (format.GetType() == typeof(BitmapFormat))
                {
                    AssertionHelpers.AssertImagesAreIdentical(
                        original,
                        imageFactory.Image,
                        "because the alpha operation should not have been applied on {0}",
                        imageFactory.ImagePath);
                }
                else
                {
                    AssertionHelpers.AssertImagesAreDifferent(
                        original,
                        imageFactory.Image,
                        "because the alpha operation should have been applied on {0}",
                        imageFactory.ImagePath);
                }
            }
        }
        public void FilterIsApplied()
        {
            foreach (ImageFactory imageFactory in this.ListInputImages())
            {
                Image original = (Image)imageFactory.Image.Clone();

                List <IMatrixFilter> filters = new List <IMatrixFilter>
                {
                    MatrixFilters.BlackWhite,
                    MatrixFilters.Comic,
                    MatrixFilters.Gotham,
                    MatrixFilters.GreyScale,
                    MatrixFilters.HiSatch,
                    MatrixFilters.Invert,
                    MatrixFilters.Lomograph,
                    MatrixFilters.LoSatch,
                    MatrixFilters.Polaroid,
                    MatrixFilters.Sepia
                };

                foreach (IMatrixFilter filter in filters)
                {
                    imageFactory.Filter(filter);
                    AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the filter operation should have been applied on {0}", imageFactory.ImagePath);
                    imageFactory.Reset();
                    AssertionHelpers.AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset");
                }
            }
        }
        public void EdgeDetectionEffectIsApplied()
        {
            int i = 0;

            foreach (ImageFactory imageFactory in this.ListInputImages())
            {
                Image original = (Image)imageFactory.Image.Clone();

                List <IEdgeFilter> filters = new List <IEdgeFilter>
                {
                    new KayyaliEdgeFilter(),
                    new KirschEdgeFilter(),
                    new Laplacian3X3EdgeFilter(),
                    new Laplacian5X5EdgeFilter(),
                    new LaplacianOfGaussianEdgeFilter(),
                    new PrewittEdgeFilter(),
                    new RobertsCrossEdgeFilter(),
                    new ScharrEdgeFilter(),
                    new SobelEdgeFilter()
                };

                int j = 0;
                foreach (IEdgeFilter filter in filters)
                {
                    imageFactory.DetectEdges(filter);
                    AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the edge operation should have been applied on {0}", imageFactory.ImagePath);
                    imageFactory.Reset();
                    AssertionHelpers.AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset");

                    imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/edgefilter-" + j++.ToString() + "-image-" + i.ToString() + ".jpg");
                }

                i++;
            }
        }
Ejemplo n.º 5
0
        public void AlphaIsModified()
        {
            int i = 0;

            foreach (ImageFactory imageFactory in this.ListInputImages())
            {
                Image original = (Image)imageFactory.Image.Clone();
                imageFactory.Alpha(50);

                if (imageFactory.CurrentImageFormat.GetType() == typeof(BitmapFormat))
                {
                    AssertionHelpers.AssertImagesAreIdentical(
                        original,
                        imageFactory.Image,
                        "because the alpha operation should not have been applied on {0}",
                        imageFactory.ImagePath);
                }
                else
                {
                    AssertionHelpers.AssertImagesAreDifferent(
                        original,
                        imageFactory.Image,
                        "because the alpha operation should have been applied on {0}",
                        imageFactory.ImagePath);
                }

                imageFactory.Format(new JpegFormat()).Save("./output/alpha-" + i++ + ".jpg");
            }
        }
        public void FilterIsApplied()
        {
            int i = 0;

            foreach (ImageFactory imageFactory in this.ListInputImages(".bmp"))
            {
                using (Image original = imageFactory.Image.Copy())
                {
                    List <IMatrixFilter> filters = new List <IMatrixFilter>
                    {
                        MatrixFilters.BlackWhite,
                        MatrixFilters.Comic,
                        MatrixFilters.Gotham,
                        MatrixFilters.GreyScale,
                        MatrixFilters.HiSatch,
                        MatrixFilters.Invert,
                        MatrixFilters.Lomograph,
                        MatrixFilters.LoSatch,
                        MatrixFilters.Polaroid,
                        MatrixFilters.Sepia
                    };

                    int j = 0;
                    foreach (IMatrixFilter filter in filters)
                    {
                        imageFactory.Filter(filter);

                        AssertionHelpers.AssertImagesAreDifferent(
                            original,
                            imageFactory.Image,
                            "because the {0} filter operation should have been applied on {1}",
                            filter.GetType().Name,
                            imageFactory.ImagePath);

                        imageFactory.Format(new JpegFormat())
                        .Save(OutputPath + "filter-" + j++ + "-image-" + i + ".jpg");

                        imageFactory.Reset();

                        AssertionHelpers.AssertImagesAreIdentical(
                            original,
                            imageFactory.Image,
                            "because the image should be reset");
                    }

                    i++;
                }
            }
        }
Ejemplo n.º 7
0
        public void ResizeIsApplied()
        {
            Size        stretchedSize = new Size(400, 400);
            ResizeLayer stretchLayer  = new ResizeLayer(stretchedSize, ResizeMode.Stretch);

            Size paddedSize = new Size(700, 700);
            // ReSharper disable once RedundantArgumentDefaultValue
            ResizeLayer paddedLayer = new ResizeLayer(paddedSize, ResizeMode.Pad);

            Size        cropSize  = new Size(600, 450);
            ResizeLayer cropLayer = new ResizeLayer(cropSize, ResizeMode.Crop);

            Size        minSize  = new Size(300, 300);
            ResizeLayer minLayer = new ResizeLayer(minSize, ResizeMode.Min);

            int i = 0;

            foreach (ImageFactory imageFactory in this.ListInputImages())
            {
                Image original = (Image)imageFactory.Image.Clone();

                // First stretch
                imageFactory.Format(new JpegFormat()).Resize(stretchLayer);
                AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the resize operation should have been applied on {0}", imageFactory.ImagePath);

                Assert.AreEqual(imageFactory.Image.Size, stretchedSize);
                imageFactory.Save("./output/resize-stretch-" + i + ".jpg");

                // Check we padd correctly.
                imageFactory.Resize(paddedLayer);
                Assert.AreEqual(imageFactory.Image.Size, paddedSize);
                imageFactory.Save("./output/resize-padd-" + i + ".jpg");

                // Check we crop correctly.
                imageFactory.Resize(cropLayer);
                Assert.AreEqual(imageFactory.Image.Size, cropSize);
                imageFactory.Save("./output/resize-crop-" + i + ".jpg");

                // Check we min correctly using the shortest size.
                imageFactory.Resize(minLayer);
                Assert.AreEqual(imageFactory.Image.Size, new Size(400, 300));
                imageFactory.Save("./output/resize-crop-" + i + ".jpg");

                imageFactory.Reset();
                AssertionHelpers.AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset");

                imageFactory.Format(new JpegFormat()).Save("./output/resize-" + i + ".jpg");
            }
        }
        public void HueIsModified()
        {
            foreach (ImageFactory imageFactory in this.ListInputImages())
            {
                Image original = (Image)imageFactory.Image.Clone();
                imageFactory.Hue(90);
                AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the hue operation should have been applied on {0}", imageFactory.ImagePath);

                imageFactory.Reset();
                AssertionHelpers.AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset");

                imageFactory.Hue(116, true);
                AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the hue+rotate operation should have been applied on {0}", imageFactory.ImagePath);
            }
        }
        public void ImageIsFlipped()
        {
            foreach (ImageFactory imageFactory in this.ListInputImages())
            {
                Image original = (Image)imageFactory.Image.Clone();
                imageFactory.Flip(true);
                AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the vertical flip operation should have been applied on {0}", imageFactory.ImagePath);
                imageFactory.Image.Width.Should().Be(original.Width, "because the dimensions should not have changed");
                imageFactory.Image.Height.Should().Be(original.Height, "because the dimensions should not have changed");
                imageFactory.Reset();
                AssertionHelpers.AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset");

                imageFactory.Flip();
                AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the horizontal flip operation should have been applied on {0}", imageFactory.ImagePath);
                imageFactory.Image.Width.Should().Be(original.Width, "because the dimensions should not have changed");
                imageFactory.Image.Height.Should().Be(original.Height, "because the dimensions should not have changed");
            }
        }
        public void HueIsModified()
        {
            int i = 0;

            foreach (ImageFactory imageFactory in this.ListInputImages())
            {
                Image original = (Image)imageFactory.Image.Clone();
                imageFactory.Hue(90);
                AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the hue operation should have been applied on {0}", imageFactory.ImagePath);

                imageFactory.Reset();
                AssertionHelpers.AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset");

                imageFactory.Hue(116, true);
                AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the hue+rotate operation should have been applied on {0}", imageFactory.ImagePath);

                imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/hue-" + i++.ToString() + ".jpg");
            }
        }
        public void ImageIsFlipped()
        {
            int i = 0;

            foreach (ImageFactory imageFactory in this.ListInputImages())
            {
                using (Image original = imageFactory.Image.Copy())
                {
                    imageFactory.Flip(true);
                    AssertionHelpers.AssertImagesAreDifferent(
                        original,
                        imageFactory.Image,
                        "because the vertical flip operation should have been applied on {0}",
                        imageFactory.ImagePath);
                    imageFactory.Image.Width.Should()
                    .Be(original.Width, "because the dimensions should not have changed");
                    imageFactory.Image.Height.Should()
                    .Be(original.Height, "because the dimensions should not have changed");
                    imageFactory.Reset();
                    AssertionHelpers.AssertImagesAreIdentical(
                        original,
                        imageFactory.Image,
                        "because the image should be reset");

                    imageFactory.Flip();
                    AssertionHelpers.AssertImagesAreDifferent(
                        original,
                        imageFactory.Image,
                        "because the horizontal flip operation should have been applied on {0}",
                        imageFactory.ImagePath);
                    imageFactory.Image.Width.Should()
                    .Be(original.Width, "because the dimensions should not have changed");
                    imageFactory.Image.Height.Should()
                    .Be(original.Height, "because the dimensions should not have changed");

                    imageFactory.Format(new JpegFormat()).Save(OutputPath + "flip-" + i++ + ".jpg");
                }
            }
        }
        public void HueIsModified()
        {
            int i = 0;

            foreach (ImageFactory imageFactory in this.ListInputImages(".bmp"))
            {
                using (Image original = imageFactory.Image.Copy())
                {
                    imageFactory.Hue(90);
                    AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image,
                                                              "because the hue operation should have been applied on {0}", imageFactory.ImagePath);

                    imageFactory.Reset();
                    AssertionHelpers.AssertImagesAreIdentical(original, imageFactory.Image,
                                                              "because the image should be reset");

                    imageFactory.Hue(116, true);
                    AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image,
                                                              "because the hue+rotate operation should have been applied on {0}", imageFactory.ImagePath);

                    imageFactory.Format(new BitmapFormat()).Save(OutputPath + "hue-" + i++ + ".jpg");
                }
            }
        }
        public void FilterIsApplied()
        {
            int i = 0;

            foreach (ImageFactory imageFactory in this.ListInputImages())
            {
                Image original = (Image)imageFactory.Image.Clone();

                List <IMatrixFilter> filters = new List <IMatrixFilter>
                {
                    MatrixFilters.BlackWhite,
                    MatrixFilters.Comic,
                    MatrixFilters.Gotham,
                    MatrixFilters.GreyScale,
                    MatrixFilters.HiSatch,
                    MatrixFilters.Invert,
                    MatrixFilters.Lomograph,
                    MatrixFilters.LoSatch,
                    MatrixFilters.Polaroid,
                    MatrixFilters.Sepia
                };

                int j = 0;
                foreach (IMatrixFilter filter in filters)
                {
                    imageFactory.Filter(filter);
                    AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the filter operation should have been applied on {0}", imageFactory.ImagePath);
                    imageFactory.Reset();
                    AssertionHelpers.AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset");

                    imageFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat()).Save("./output/filter-" + j++.ToString() + "-image-" + i.ToString() + ".jpg");
                }

                i++;
            }
        }
        public void ResizeIsApplied()
        {
            Size        stretchedSize = new Size(400, 400);
            ResizeLayer stretchLayer  = new ResizeLayer(stretchedSize, ResizeMode.Stretch);

            Size paddedSize = new Size(700, 700);
            // ReSharper disable once RedundantArgumentDefaultValue
            ResizeLayer paddedLayer = new ResizeLayer(paddedSize, ResizeMode.Pad);

            Size        cropSize  = new Size(600, 450);
            ResizeLayer cropLayer = new ResizeLayer(cropSize, ResizeMode.Crop);

            Size        minSize  = new Size(300, 300);
            ResizeLayer minLayer = new ResizeLayer(minSize, ResizeMode.Min);

            Size padSingleDimensionWidthSize = new Size(400, 0);
            // ReSharper disable once RedundantArgumentDefaultValue
            ResizeLayer paddedSingleDimensionWidthLayer = new ResizeLayer(padSingleDimensionWidthSize, ResizeMode.Pad);

            Size padSingleDimensionHeightSize = new Size(0, 300);
            // ReSharper disable once RedundantArgumentDefaultValue
            ResizeLayer paddedSingleDimensionHeightLayer = new ResizeLayer(padSingleDimensionHeightSize, ResizeMode.Pad);

            Size        boxPadSingleDimensionWidthSize  = new Size(400, 0);
            ResizeLayer boxPadSingleDimensionWidthLayer = new ResizeLayer(boxPadSingleDimensionWidthSize, ResizeMode.BoxPad);

            Size        boxPadSingleDimensionHeightSize  = new Size(0, 300);
            ResizeLayer boxPadSingleDimensionHeightLayer = new ResizeLayer(boxPadSingleDimensionHeightSize, ResizeMode.BoxPad);

            int i = 0;

            foreach (ImageFactory imageFactory in this.ListInputImages(".gif"))
            {
                Image original = imageFactory.Image.Copy();

                // First stretch
                imageFactory.Format(new JpegFormat()).Resize(stretchLayer);
                AssertionHelpers.AssertImagesAreDifferent(original, imageFactory.Image, "because the resize operation should have been applied on {0}", imageFactory.ImagePath);

                Assert.AreEqual(imageFactory.Image.Size, stretchedSize);
                imageFactory.Save(OutputPath + "resize-stretch-" + i + ".jpg");

                // Check we padd correctly.
                imageFactory.Resize(paddedLayer);
                Assert.AreEqual(imageFactory.Image.Size, paddedSize);
                imageFactory.Save(OutputPath + "resize-padd-" + i + ".jpg");

                // Check we crop correctly.
                imageFactory.Resize(cropLayer);
                Assert.AreEqual(imageFactory.Image.Size, cropSize);
                imageFactory.Save(OutputPath + "resize-crop-" + i + ".jpg");

                // Check we min correctly using the shortest size.
                imageFactory.Resize(minLayer);
                Assert.AreEqual(imageFactory.Image.Size, new Size(400, 300));
                imageFactory.Save(OutputPath + "resize-crop-" + i + ".jpg");

                // Check padding with only a single dimension specified (width)
                imageFactory.Resize(paddedSingleDimensionWidthLayer);
                Assert.AreEqual(imageFactory.Image.Size, new Size(400, 300));
                imageFactory.Save(OutputPath + "resize-padsingledimension-width-" + i + ".jpg");

                // Check padding with only a single dimension specified (height)
                imageFactory.Resize(paddedSingleDimensionHeightLayer);
                Assert.AreEqual(imageFactory.Image.Size, new Size(400, 300));
                imageFactory.Save(OutputPath + "resize-padsingledimension-height-" + i + ".jpg");

                // Check box padding with only a single dimension specified (width)
                imageFactory.Resize(boxPadSingleDimensionWidthLayer);
                Assert.AreEqual(imageFactory.Image.Size, new Size(400, 300));
                imageFactory.Save(OutputPath + "resize-boxpadsingledimension-width-" + i + ".jpg");

                // Check box padding with only a single dimension specified (height)
                imageFactory.Resize(boxPadSingleDimensionHeightLayer);
                Assert.AreEqual(imageFactory.Image.Size, new Size(400, 300));
                imageFactory.Save(OutputPath + "resize-boxpadsingledimension-height-" + i + ".jpg");

                imageFactory.Reset();
                AssertionHelpers.AssertImagesAreIdentical(original, imageFactory.Image, "because the image should be reset");

                imageFactory.Format(new JpegFormat()).Save(OutputPath + "resize-" + i + ".jpg");
            }
        }