public static void TestHaarInputOutput(string imageInPath) { var image = ReadImageGrayscale(imageInPath); #region Wavelet Compress Methods // Test HaarWaveletTransform var inputMatrix = new Matrix(image); inputMatrix.WriteCSV("haar-before.csv"); HaarWaveletTransform.HaarTransform2D(image, inputMatrix.Rows, inputMatrix.Columns); Matrix haarMatrixInverse = inputMatrix.Copy(); HaarWaveletTransform.InverseHaarTransform2D(haarMatrixInverse.MatrixData, haarMatrixInverse.Rows, haarMatrixInverse.Columns); haarMatrixInverse.WriteCSV("haar-after.csv"); haarMatrixInverse.DrawMatrixImage("haar-transform-forward-and-backward.png", -1, -1, false); // Test Wavelet Compress and Decompress in one step const int compLevels = 8; const int compTreshold = 150; Matrix haarMatrixCompDecomp = haarMatrixInverse.Copy(); WaveletComDec.CompressDecompress2D(haarMatrixCompDecomp.MatrixData, compLevels, compTreshold); haarMatrixCompDecomp.DrawMatrixImage("haar-compress-and-decompress-combined.png", -1, -1, false); // Test Compress and Decompress in two steps int lastHeight = 0; int lastWidth = 0; Matrix haarMatrixComp = haarMatrixInverse.Copy(); WaveletCompress.Compress2D(haarMatrixComp.MatrixData, compLevels, compTreshold, out lastHeight, out lastWidth); WaveletDecompress.Decompress2D(haarMatrixComp.MatrixData, compLevels, lastHeight, lastWidth); haarMatrixComp.DrawMatrixImage("haar-compress-and-decompress.png", -1, -1, false); #endregion #region Test using HaarCSharp // Test HaarCSharp using iterations const int haarCSharpIterations = 3; Matrix haarMatrixCSharp = haarMatrixInverse.Copy(); ForwardWaveletTransform.Transform2D(haarMatrixCSharp.MatrixData, false, haarCSharpIterations); haarMatrixCSharp.DrawMatrixImage("haar-forward.png", -1, -1, false); InverseWaveletTransform.Transform2D(haarMatrixCSharp.MatrixData, false, haarCSharpIterations); haarMatrixCSharp.DrawMatrixImage("haar-inverse.png", -1, -1, false); // Test HaarCSharp using all levels and only 1 iteration Matrix haarMatrixCSharpAll = haarMatrixInverse.Copy(); ForwardWaveletTransform.Transform2D(haarMatrixCSharpAll.MatrixData, true, 1); haarMatrixCSharpAll.DrawMatrixImage("haar-forward-all.png", -1, -1, false); InverseWaveletTransform.Transform2D(haarMatrixCSharpAll.MatrixData, true, 1); haarMatrixCSharpAll.DrawMatrixImage("haar-inverse-all.png", -1, -1, false); #endregion }
public static void TestHaarWaveletTransform2D() { Console.WriteLine(); Console.WriteLine("The Haar Wavelet Transform 2D (with only one iteration)"); double[][] mat = Get2DTestData(); HaarWaveletTransform.HaarTransform2D(mat, 4, 4); var result = new Matrix(mat); result.PrintPretty(); Assert.That(mat, Is.EqualTo(Get2DResultDataFirstIteration()).AsCollection.Within(0.001), "fail at [0]"); HaarWaveletTransform.InverseHaarTransform2D(mat, 4, 4); result.PrintPretty(); Assert.That(mat, Is.EqualTo(Get2DTestData()).AsCollection.Within(0.001), "fail at [0]"); }