public void TestConcate() { Matrix<float> mat = new Matrix<float>(30, 40); mat.SetRandUniform(new MCvScalar(0), new MCvScalar(255)); Matrix<float> m1 = mat.GetSubRect(new Rectangle(0, 0, mat.Cols, 20)); Matrix<float> m2 = mat.GetSubRect(new Rectangle(0, 20, mat.Cols, mat.Rows - 20)); Matrix<float> mat2 = m1.ConcateVertical(m2); Assert.IsTrue(mat.Equals(mat2)); Matrix<float> m3 = mat.GetSubRect(new Rectangle(0, 0, 10, mat.Rows)); Matrix<float> m4 = mat.GetSubRect(new Rectangle(10, 0, mat.Cols - 10, mat.Rows)); Matrix<float> mat3 = m3.ConcateHorizontal(m4); Assert.IsTrue(mat.Equals(mat3)); Matrix<float> m5 = mat.GetRows(0, 5, 1); Matrix<float> m6 = mat.GetRows(5, 6, 1); Matrix<float> m7 = mat.GetRows(6, mat.Rows, 1); Assert.IsTrue(mat.RemoveRows(5, 6).Equals(m5.ConcateVertical(m7))); Assert.IsTrue(mat.RemoveRows(0, 1).Equals(mat.GetRows(1, mat.Rows, 1))); Assert.IsTrue(mat.RemoveRows(mat.Rows - 1, mat.Rows).Equals(mat.GetRows(0, mat.Rows - 1, 1))); }
public void TestSubMatrix() { Matrix<float> mat = new Matrix<float>(30, 40); mat.SetRandUniform(new MCvScalar(0), new MCvScalar(255)); Matrix<float> submat = mat.GetSubRect(new Rectangle(5, 5, 15, 15)); for (int i = 0; i < 15; i++) for (int j = 0; j < 15; j++) EmguAssert.AreEqual(mat[i + 5, j + 5], submat[i, j]); Matrix<float> secondRow = mat.GetRow(1); for (int i = 0; i < mat.Cols; i++) { EmguAssert.AreEqual(mat[1, i], secondRow[0, i]); } Matrix<float> thirdCol = mat.GetCol(2); for (int i = 0; i < mat.Rows; i++) { EmguAssert.AreEqual(mat[i, 2], thirdCol[i, 0]); } Matrix<float> diagonal = mat.GetDiag(); for (int i = 0; i < Math.Min(mat.Rows, mat.Cols); i++) { EmguAssert.AreEqual(diagonal[i, 0], mat[i, i]); } }
public void TestImageDFT() { Image<Gray, float> matA = EmguAssert.LoadImage<Gray, float>("stuff.jpg"); //The matrix to be convolved with matA, a bluring filter Matrix<float> matB = new Matrix<float>( new float[,] { {1.0f / 16.0f, 1.0f / 16.0f, 1.0f / 16.0f}, {1.0f / 16.0f, 8.0f / 16.0f, 1.0f / 16.0f}, {1.0f / 16.0f, 1.0f / 16.0f, 1.0f / 16.0f}}); Image<Gray, float> convolvedImage = new Image<Gray, float>(new Size(matA.Width + matB.Width -1, matA.Height + matB.Height -1)); Matrix<float> dftA = new Matrix<float>( CvInvoke.GetOptimalDFTSize(convolvedImage.Rows), CvInvoke.GetOptimalDFTSize(convolvedImage.Cols)); matA.CopyTo(dftA.GetSubRect(matA.ROI)); CvInvoke.Dft(dftA, dftA, Emgu.CV.CvEnum.DxtType.Forward, matA.Rows); Matrix<float> dftB = new Matrix<float>(dftA.Size); matB.CopyTo(dftB.GetSubRect(new Rectangle(Point.Empty, matB.Size))); CvInvoke.Dft(dftB, dftB, Emgu.CV.CvEnum.DxtType.Forward, matB.Rows); CvInvoke.MulSpectrums(dftA, dftB, dftA, Emgu.CV.CvEnum.MulSpectrumsType.Default, false); CvInvoke.Dft(dftA, dftA, Emgu.CV.CvEnum.DxtType.Inverse, convolvedImage.Rows); dftA.GetSubRect(new Rectangle(Point.Empty, convolvedImage.Size)).CopyTo(convolvedImage); }
public void TestImageDFT() { Image<Gray, float> matA = new Image<Gray, float>("stuff.jpg"); //The matrix to be convoled with matA, a bluring filter Matrix<float> matB = new Matrix<float>( new float[,] { {1.0f/16.0f, 1.0f/16.0f, 1.0f/16.0f}, {1.0f/16.0f, 8.0f/16.0f, 1.0f/16.0f}, {1.0f/16.0f, 1.0f/16.0f, 1.0f/16.0f}}); Image<Gray, float> convolvedImage = new Image<Gray, float>(matA.Size + matB.Size - new Size(1, 1)); Matrix<float> dftA = new Matrix<float>( CvInvoke.cvGetOptimalDFTSize(convolvedImage.Rows), CvInvoke.cvGetOptimalDFTSize(convolvedImage.Cols)); matA.CopyTo(dftA.GetSubRect(matA.ROI)); CvInvoke.cvDFT(dftA, dftA, Emgu.CV.CvEnum.CV_DXT.CV_DXT_FORWARD, matA.Rows); Matrix<float> dftB = new Matrix<float>(dftA.Size); matB.CopyTo(dftB.GetSubRect(new Rectangle(Point.Empty, matB.Size))); CvInvoke.cvDFT(dftB, dftB, Emgu.CV.CvEnum.CV_DXT.CV_DXT_FORWARD, matB.Rows); CvInvoke.cvMulSpectrums(dftA, dftB, dftA, Emgu.CV.CvEnum.MUL_SPECTRUMS_TYPE.DEFAULT); CvInvoke.cvDFT(dftA, dftA, Emgu.CV.CvEnum.CV_DXT.CV_DXT_INVERSE, convolvedImage.Rows); dftA.GetSubRect(new Rectangle(Point.Empty, convolvedImage.Size)).CopyTo(convolvedImage); }