Esempio n. 1
0
 public Wavelet(WaveletType name)
 {
     this.wavelet_type =  name;
     if (this.wavelet_type == WaveletType.Daubechie3) {
         this.low_pass_filter_coef = daubechie3_low_pass_coefs;
         this.high_pass_filter_coef = daubechie3_high_pass_coefs;
     }
 }
Esempio n. 2
0
        private static double[,] DecodeChannel(double[,] channel, WaveletType waveletType, int iterationsCount)
        {
            var lowerCoefs  = GetCoefsByWaveletType(waveletType);
            var higherCoefs = GetHighPassFilter(lowerCoefs);

            double[] iLowerCoefs, iHigherCoefs;
            GetInverseCoefs(lowerCoefs, higherCoefs, out iLowerCoefs, out iHigherCoefs);

            var height         = channel.GetLength(0);
            var width          = channel.GetLength(1);
            var orderedChannel = new double[height, width];

            height >>= iterationsCount - 1;
            width  >>= iterationsCount - 1;

            for (var counter = 0; counter < iterationsCount; ++counter)
            {
                for (var i = 0; i < height; ++i)
                {
                    for (var j = 0; j < width; ++j)
                    {
                        orderedChannel[i, j] = channel[i % 2 == 0 ? i / 2 : height / 2 + i / 2, j % 2 == 0 ? j / 2 : width / 2 + j / 2];
                    }
                }
                var line = new double[height];
                for (var j = 0; j < width; ++j)
                {
                    for (var i = 0; i < height; ++i)
                    {
                        line[i] = orderedChannel[i, j];
                    }
                    var resultLine = PairConvolution(line, iLowerCoefs, iHigherCoefs, iLowerCoefs.Length - 2);
                    for (var i = 0; i < height; ++i)
                    {
                        channel[i, j] = resultLine[i];
                    }
                }
                line = new double[width];
                for (var i = 0; i < height; ++i)
                {
                    for (var j = 0; j < width; ++j)
                    {
                        line[j] = channel[i, j];
                    }
                    var resultLine = PairConvolution(line, iLowerCoefs, iHigherCoefs, iLowerCoefs.Length - 2);
                    for (var j = 0; j < width; ++j)
                    {
                        channel[i, j] = resultLine[j];
                    }
                }

                height <<= 1;
                width  <<= 1;
            }
            return(channel);
        }
Esempio n. 3
0
        static IntPtr GetNativeWaveletType(WaveletType waveletType)
        {
            switch (waveletType)
            {
            case WaveletType.Haar: return(Native.GetWaveletTypeHaar());

            case WaveletType.Daubechies: return(Native.GetWaveletTypeDaubechies());

            case WaveletType.BSpline: return(Native.GetWaveletTypeBSpline());

            default: throw new ArgumentException("parameter 'waveletType' is not a valid wavelet type");
            }
        }
Esempio n. 4
0
        private static double[] GetCoefsByWaveletType(WaveletType waveletType)
        {
            switch (waveletType)
            {
            case WaveletType.Haar1:
                return(new[]
                {
                    1.0 / 2,
                    1.0 / 2,
                });

            case WaveletType.Haar2:
                return(new[]
                {
                    1.0 / Math.Sqrt(2.0),
                    1.0 / Math.Sqrt(2.0)
                });

            case WaveletType.D4:
                return(new[]
                {
                    (1 + Math.Sqrt(3)) / (4 * Math.Sqrt(2)),
                    (3 + Math.Sqrt(3)) / (4 * Math.Sqrt(2)),
                    (3 - Math.Sqrt(3)) / (4 * Math.Sqrt(2)),
                    (1 - Math.Sqrt(3)) / (4 * Math.Sqrt(2))
                });

            case WaveletType.D6:
                return(new[]
                {
                    0.47046721 / Math.Sqrt(2),
                    1.14111692 / Math.Sqrt(2),
                    0.650365 / Math.Sqrt(2),
                    -0.19093442 / Math.Sqrt(2),
                    -0.12083221 / Math.Sqrt(2),
                    0.0498175 / Math.Sqrt(2),
                });

            default:
                throw new ArgumentOutOfRangeException("waveletType", waveletType, null);
            }
        }
        public Wavelet(WaveletType waveletType, double[] decLowPass)
        {
            WaveletType        = waveletType;
            DecompositionLow   = decLowPass;
            DecompositionHigh  = new double[decLowPass.Length];
            ReconstructionLow  = new double[decLowPass.Length];
            ReconstructionHigh = new double[decLowPass.Length];

            for (int i = 0; i < decLowPass.Length; i++)
            {
                DecompositionHigh[i] = decLowPass[decLowPass.Length - i - 1];
                if (i % 2 != 0)
                {
                    DecompositionHigh[i] *= -1;
                }
                ReconstructionLow[i] = decLowPass[decLowPass.Length - i - 1];
            }
            for (int i = 0; i < decLowPass.Length; i++)
            {
                ReconstructionHigh[i] = DecompositionHigh[decLowPass.Length - i - 1];
            }
        }
Esempio n. 6
0
 public WaveletTransformer(WaveletType waveletType, int waveletParameter)
 {
     this.wavelet = Native.CreateWavelet(GetNativeWaveletType(waveletType), (uint)waveletParameter);
 }