Ejemplo n.º 1
0
        public static void TestHaar1d()
        {
            int i = 0;

            double[] vec3 = { 4, 2, 5, 5 };

            Haar.Haar1d(vec3, 4);

            Console.Write("The 1D Haar Transform: ");
            Console.Write("\n");
            for (i = 0; i < 4; i++)
            {
                Console.Write(vec3[i]);
                Console.Write(" ");
            }
            Console.Write("\n");
        }
Ejemplo n.º 2
0
        public static Matrix GetWaveletTransformedMatrix(double[][] image, WaveletMethod waveletMethod)
        {
            int width  = image[0].Length;
            int height = image.Length;

            Matrix dwtMatrix = null;

            Stopwatch stopWatch = Stopwatch.StartNew();
            long      startS    = stopWatch.ElapsedTicks;

            switch (waveletMethod)
            {
            case WaveletMethod.Dwt:
                Wavelets.Dwt dwt         = new Wavelets.Dwt(8);
                Matrix       imageMatrix = new Matrix(image);
                dwtMatrix = dwt.Transform(imageMatrix);
                break;

            case WaveletMethod.Haar:
                Haar.Haar2d(image, height, width);
                dwtMatrix = new Matrix(image);
                break;

            case WaveletMethod.HaarTransformTensor:                     // This is using the tensor product layout
                dwtMatrix = HaarWaveletTransform(image);
                break;

            case WaveletMethod.HaarWaveletDecompositionTensor:                     // This is using the tensor product layout
                StandardHaarWaveletDecomposition haar = new StandardHaarWaveletDecomposition();
                haar.DecomposeImageInPlace(image);
                dwtMatrix = new Matrix(image);
                break;

            case WaveletMethod.HaarWaveletDecomposition:
                StandardHaarWaveletDecomposition haarNew = new StandardHaarWaveletDecomposition(false);
                haarNew.DecomposeImageInPlace(image);
                dwtMatrix = new Matrix(image);
                break;

            case WaveletMethod.NonStandardHaarWaveletDecomposition:
                NonStandardHaarWaveletDecomposition haarNonStandard = new NonStandardHaarWaveletDecomposition();
                haarNonStandard.DecomposeImageInPlace(image);
                dwtMatrix = new Matrix(image);
                break;

            case WaveletMethod.JWaveTensor:                     // This is using the tensor product layout
                WaveletInterface wavelet = null;
                wavelet = new Haar02();
                //wavelet = new Daub02();
                TransformInterface bWave = null;
                bWave = new FastWaveletTransform(wavelet);
                //bWave = new WaveletPacketTransform(wavelet);
                //bWave = new DiscreteWaveletTransform(wavelet);
                Transform  t        = new Transform(bWave);                 // perform all steps
                double[][] dwtArray = t.forward(image);
                dwtMatrix = new Matrix(dwtArray);
                break;

            case WaveletMethod.HaarWaveletCompress:
                int lastHeight = 0;
                int lastWidth  = 0;
                Compress.WaveletCompress.HaarTransform2D(image, 10000, out lastHeight, out lastWidth);
                dwtMatrix = new Matrix(image);
                break;

            default:
                break;
            }

            long endS = stopWatch.ElapsedTicks;

            Console.WriteLine("WaveletMethod: {0} Time in ticks: {1}", Enum.GetName(typeof(WaveletMethod), waveletMethod), (endS - startS));

            //dwtMatrix.WriteCSV("HaarImageNormalized.csv", ";");

            // increase all values
            double[][] haarImageNormalized5k = dwtMatrix.MatrixData.Select(i => i.Select(j => j * 5000).ToArray()).ToArray();
            //Matrix haarImageNormalized5kMatrix = new Matrix(haarImageNormalized5k);
            //haarImageNormalized5kMatrix.WriteCSV("HaarImageNormalized5k.csv", ";");

            // convert to byte values (0 - 255)
            // duplicate the octave/ matlab method uint8
            double[][] uint8 = new double[haarImageNormalized5k.Length][];
            for (int i = 0; i < haarImageNormalized5k.Length; i++)
            {
                uint8[i] = new double[haarImageNormalized5k.Length];
                for (int j = 0; j < haarImageNormalized5k[i].Length; j++)
                {
                    double v = haarImageNormalized5k[i][j];
                    if (v > 255)
                    {
                        uint8[i][j] = 255;
                    }
                    else if (v < 0)
                    {
                        uint8[i][j] = 0;
                    }
                    else
                    {
                        uint8[i][j] = (byte)haarImageNormalized5k[i][j];
                    }
                }
            }

            Matrix uint8Matrix = new Matrix(uint8);

            //uint8Matrix.WriteCSV("Uint8HaarImageNormalized5k.csv", ";");
            return(uint8Matrix);
        }