Exemplo n.º 1
0
        public void SetRow_InvalidNumberOfValues_ThrowsException()
        {
            ConvolveMatrix matrix = new ConvolveMatrix(1);

            ExceptionAssert.ThrowsArgumentException("values", () =>
            {
                matrix.SetRow(0, 1, 2, 3);
            });
        }
Exemplo n.º 2
0
        private static void SetColumn_InvalidColumn_ThrowsException(int x)
        {
            ConvolveMatrix matrix = new ConvolveMatrix(1);

            ExceptionAssert.ThrowsArgumentOutOfRangeException("x", () =>
            {
                matrix.SetColumn(x, 1.0, 2.0);
            });
        }
Exemplo n.º 3
0
        private static void Indexer_InvalidIndex_ThrowsException(string paramName, int x, int y)
        {
            ConvolveMatrix matrix = new ConvolveMatrix(1);

            ExceptionAssert.ThrowsArgumentOutOfRangeException(paramName, () =>
            {
                double foo = matrix[x, y];
            });
        }
Exemplo n.º 4
0
        public void SetColumn_InvalidNumberOfValues_ThrowsException()
        {
            var matrix = new ConvolveMatrix(1);

            ExceptionAssert.Throws <ArgumentException>("values", () =>
            {
                matrix.SetColumn(0, 1, 2, 3);
            });
        }
Exemplo n.º 5
0
        private static void SetRow_InvalidRow_ThrowsException(int y)
        {
            ConvolveMatrix matrix = new ConvolveMatrix(1);

            ExceptionAssert.ThrowsArgumentOutOfRangeException("y", () =>
            {
                matrix.SetRow(y, 1.0, 2.0);
            });
        }
Exemplo n.º 6
0
        private static void SetValue_InvalidIndex_ThrowsException(string paramName, int x, int y)
        {
            ConvolveMatrix matrix = new ConvolveMatrix(1);

            ExceptionAssert.ThrowsArgumentOutOfRangeException(paramName, () =>
            {
                matrix.SetValue(x, y, 1);
            });
        }
Exemplo n.º 7
0
        public void SetColumn_ValuesIsNull_ThrowsException()
        {
            var matrix = new ConvolveMatrix(1);

            ExceptionAssert.Throws <ArgumentNullException>("values", () =>
            {
                matrix.SetColumn(0, null);
            });
        }
Exemplo n.º 8
0
        private static void GetValue_InvalidIndex_ThrowsException(string paramName, int x, int y)
        {
            var matrix = new ConvolveMatrix(1);

            Assert.Throws <ArgumentOutOfRangeException>(paramName, () =>
            {
                matrix.GetValue(x, y);
            });
        }
Exemplo n.º 9
0
        public void SetRowValuesIsNull_ThrowsException()
        {
            ConvolveMatrix matrix = new ConvolveMatrix(1);

            ExceptionAssert.ThrowsArgumentNullException("values", () =>
            {
                matrix.SetRow(0, null);
            });
        }
Exemplo n.º 10
0
 private static void Test_Values(ConvolveMatrix matrix)
 {
     Assert.AreEqual(0.0, matrix.GetValue(0, 0));
     Assert.AreEqual(1.0, matrix.GetValue(1, 0));
     Assert.AreEqual(2.0, matrix.GetValue(2, 0));
     Assert.AreEqual(0.1, matrix.GetValue(0, 1));
     Assert.AreEqual(1.1, matrix.GetValue(1, 1));
     Assert.AreEqual(2.1, matrix.GetValue(2, 1));
     Assert.AreEqual(0.2, matrix.GetValue(0, 2));
     Assert.AreEqual(1.2, matrix.GetValue(1, 2));
     Assert.AreEqual(2.2, matrix.GetValue(2, 2));
 }
Exemplo n.º 11
0
        public void MagickNet(string input, string output)
        {
            using (var im = new MagickImage(input))
            {
                im.Shave(100, 100);
                im.Resize(new Percentage(90.0));

                // All values in the kernel are divided by 8 (to match libvips scale behavior)
                var kernel = new ConvolveMatrix(3, -0.125, -0.125, -0.125, -0.125, 2, -0.125, -0.125, -0.125, -0.125);
                im.Convolve(kernel);

                im.Write(output);
            }
        }
Exemplo n.º 12
0
        public void SetRow_CorrectNumberOfValues_SetsColumn()
        {
            ConvolveMatrix matrix = new ConvolveMatrix(3);

            matrix.SetRow(1, 6, 8, 10);
            Assert.AreEqual(0, matrix.GetValue(0, 0));
            Assert.AreEqual(6, matrix.GetValue(0, 1));
            Assert.AreEqual(0, matrix.GetValue(0, 2));
            Assert.AreEqual(0, matrix.GetValue(1, 0));
            Assert.AreEqual(8, matrix.GetValue(1, 1));
            Assert.AreEqual(0, matrix.GetValue(1, 2));
            Assert.AreEqual(0, matrix.GetValue(2, 0));
            Assert.AreEqual(10, matrix.GetValue(2, 1));
            Assert.AreEqual(0, matrix.GetValue(2, 2));
        }
Exemplo n.º 13
0
        public void Constructor_ValidOrder_PropertiesAreSet()
        {
            ConvolveMatrix matrix = new ConvolveMatrix(3, 0.0, 1.0, 2.0, 0.1, 1.1, 2.1, 0.2, 1.2, 2.2);

            Assert.AreEqual(3, matrix.Order);
            Assert.AreEqual(0.0, matrix.GetValue(0, 0));
            Assert.AreEqual(1.0, matrix.GetValue(1, 0));
            Assert.AreEqual(2.0, matrix.GetValue(2, 0));
            Assert.AreEqual(0.1, matrix.GetValue(0, 1));
            Assert.AreEqual(1.1, matrix.GetValue(1, 1));
            Assert.AreEqual(2.1, matrix.GetValue(2, 1));
            Assert.AreEqual(0.2, matrix.GetValue(0, 2));
            Assert.AreEqual(1.2, matrix.GetValue(1, 2));
            Assert.AreEqual(2.2, matrix.GetValue(2, 2));
        }
Exemplo n.º 14
0
        public void SetValue_ValidIndex_SetsValue()
        {
            ConvolveMatrix matrix = new ConvolveMatrix(3);

            matrix.SetValue(1, 2, 1.5);

            Assert.AreEqual(0.0, matrix.GetValue(0, 0));
            Assert.AreEqual(0.0, matrix.GetValue(0, 1));
            Assert.AreEqual(0.0, matrix.GetValue(0, 2));
            Assert.AreEqual(0.0, matrix.GetValue(1, 0));
            Assert.AreEqual(0.0, matrix.GetValue(1, 1));
            Assert.AreEqual(1.5, matrix.GetValue(1, 2));
            Assert.AreEqual(0.0, matrix.GetValue(2, 0));
            Assert.AreEqual(0.0, matrix.GetValue(2, 1));
            Assert.AreEqual(0.0, matrix.GetValue(2, 2));
        }
Exemplo n.º 15
0
        public void MagickNet(string input, string output)
        {
            using var im   = new MagickImage(input);
            im.Interpolate = PixelInterpolateMethod.Bilinear;
            im.FilterType  = FilterType.Triangle;

            im.Shave(100, 100);
            im.Resize(new Percentage(90.0));

            var kernel = new ConvolveMatrix(3, -1, -1, -1, -1, 16, -1, -1, -1, -1);

            im.SetArtifact("convolve:scale", "0.125");
            im.Convolve(kernel);

            // Default quality of ImageMagick is 92, we need 75
            im.Quality = Quality;

            im.Write(output);
        }
Exemplo n.º 16
0
        public void Test_Constructor()
        {
            ExceptionAssert.Throws <ArgumentException>(delegate()
            {
                new ConvolveMatrix(-1);
            });

            ExceptionAssert.Throws <ArgumentException>(delegate()
            {
                new ConvolveMatrix(6);
            });

            new ConvolveMatrix(1);

            ExceptionAssert.Throws <ArgumentException>(delegate()
            {
                new ConvolveMatrix(2, 1.0);
            });

            ConvolveMatrix matrix = new ConvolveMatrix(3,
                                                       0.0, 1.0, 2.0,
                                                       0.1, 1.1, 2.1,
                                                       0.2, 1.2, 2.2);

            Test_Values(matrix);

            ExceptionAssert.Throws <ArgumentException>(delegate()
            {
                new ConvolveMatrix(2, null);
            });

            matrix = new ConvolveMatrix(3, new double[]
            {
                0.0, 1.0, 2.0,
                0.1, 1.1, 2.1,
                0.2, 1.2, 2.2
            });

            Test_Values(matrix);
        }
Exemplo n.º 17
0
        public void Indexer_ValidIndex_ReturnValue()
        {
            ConvolveMatrix matrix = new ConvolveMatrix(1, 8);

            Assert.AreEqual(8, matrix[0, 0]);
        }
Exemplo n.º 18
0
        public void GetValue_ValidIndex_ReturnValue()
        {
            ConvolveMatrix matrix = new ConvolveMatrix(1, 4);

            Assert.AreEqual(4, matrix.GetValue(0, 0));
        }
Exemplo n.º 19
0
        public void ToArray_ReturnsArray()
        {
            var matrix = new ConvolveMatrix(1, 6);

            Assert.Equal(new double[] { 6 }, matrix.ToArray());
        }
Exemplo n.º 20
0
        public void ToArray_ReturnsArray()
        {
            ConvolveMatrix matrix = new ConvolveMatrix(1, 6);

            CollectionAssert.AreEqual(new double[] { 6 }, matrix.ToArray());
        }