Encapsulates a convolution kernel.
Inheritance: DoubleMatrix
Ejemplo n.º 1
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));
 }
Ejemplo n.º 2
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);
    }
Ejemplo n.º 3
0
    public void Test_Convolve()
    {
      using (MagickImage image = new MagickImage("xc:", 1, 1))
      {
        image.BorderColor = MagickColors.Black;
        image.Border(5);

        Assert.AreEqual(11, image.Width);
        Assert.AreEqual(11, image.Height);

        ConvolveMatrix matrix = new ConvolveMatrix(3, 0, 0.5, 0, 0.5, 1, 0.5, 0, 0.5, 0);
        image.Convolve(matrix);

        MagickColor gray = new MagickColor("#800080008000");
        ColorAssert.AreEqual(MagickColors.Black, image, 4, 4);
        ColorAssert.AreEqual(gray, image, 5, 4);
        ColorAssert.AreEqual(MagickColors.Black, image, 6, 4);
        ColorAssert.AreEqual(gray, image, 4, 5);
        ColorAssert.AreEqual(MagickColors.White, image, 5, 5);
        ColorAssert.AreEqual(gray, image, 6, 5);
        ColorAssert.AreEqual(MagickColors.Black, image, 4, 6);
        ColorAssert.AreEqual(gray, image, 5, 6);
        ColorAssert.AreEqual(MagickColors.Black, image, 6, 6);
      }
    }