Пример #1
0
        public void RecomposeWithSafeCode()
        {
            using (var originalImage = new Bitmap(OneStepFileName))
            {
                WaveletTransform transform = new InverseWaveletTransform(1);
                ColorChannels    channels  = new SafeColorChannels(originalImage.Width, originalImage.Height);
                var imageProcessor         = new ImageProcessor(channels, transform);
                imageProcessor.ApplyTransform(originalImage);

                VerifyAsImage(originalImage);
            }
        }
Пример #2
0
        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
        }
Пример #3
0
        public void FullRecomposeWithSafeCode()
        {
            using (var originalImage = new Bitmap(DecomposedFilename))
            {
                var width          = originalImage.Width;
                var height         = originalImage.Height;
                var transform      = new InverseWaveletTransform(width, height);
                var channels       = new SafeColorChannels(width, height);
                var imageProcessor = new ImageProcessor(channels, transform);
                imageProcessor.ApplyTransform(originalImage);

                VerifyAsImage(originalImage);
            }
        }
Пример #4
0
        public static void TestHaarCSharp2D()
        {
            Console.WriteLine();
            Console.WriteLine("The HaarCSharp2D");

            double[][] mat = Get2DTestData();
            ForwardWaveletTransform.Transform2D(mat);

            var result = new Matrix(mat);

            result.PrintPretty();
            Assert.That(mat, Is.EqualTo(Get2DResultData()).AsCollection.Within(0.001), "fail at [0]");

            InverseWaveletTransform.Transform2D(mat);
            result.PrintPretty();
            Assert.That(mat, Is.EqualTo(Get2DTestData()).AsCollection.Within(0.001), "fail at [0]");
        }
Пример #5
0
        public static void TestHaarCSharp1D()
        {
            Console.WriteLine();
            Console.WriteLine("The HaarCSharp1D");

            double[] data = Get1DTestData();

            ForwardWaveletTransform.Transform1D(data, true);

            IOUtils.Print(Console.Out, data);

            // check if it's the same as
            double[] result = Get1DResultData();
            Assert.That(data, Is.EqualTo(result).AsCollection.Within(0.001), "fail at [0]");

            InverseWaveletTransform.Transform1D(data, true);

            IOUtils.Print(Console.Out, data);
            Assert.That(data, Is.EqualTo(Get1DTestData()).AsCollection.Within(0.001), "fail at [0]");
        }