Esempio n. 1
0
        private static void FlatWaveletTest(HyperspectralImage image)
        {
            IntPtr waveletData  = Marshal.AllocHGlobal(image.SizeInBytes());
            IntPtr restoredData = Marshal.AllocHGlobal(image.SizeInBytes());

            var wavelet = new Wavelet53RTransformation();

            wavelet.Encode3D(image.ToPointer(), image.ImageInfo.Width, image.ImageInfo.Height, image.ImageInfo.Bands,
                             image.ImageInfo.Width, image.ImageInfo.Height, 0, waveletData);


            wavelet.Decode3D(waveletData, image.ImageInfo.Width, image.ImageInfo.Height, image.ImageInfo.Bands,
                             image.ImageInfo.Width, image.ImageInfo.Height, 0, restoredData);

            Console.WriteLine("Flat Wavelet only. PSNR = {0}", PSNRCalculator.Calculate(image.ToPointer(), restoredData, image.ImageInfo));
            Console.WriteLine("Flat Wavelet only. MSE = {0}", PSNRCalculator.CalculateMSE(image.ToPointer(), restoredData, image.ImageInfo));

            Marshal.FreeHGlobal(waveletData);
            Marshal.FreeHGlobal(restoredData);
        }
Esempio n. 2
0
        private static void CompressTest(HyperspectralImage image, string tempPath, string restoredPath, double compression)
        {
            var sw = new Stopwatch();

            sw.Start();

            IntPtr tempData     = Marshal.AllocHGlobal(image.SizeInBytes());
            IntPtr restoredData = Marshal.AllocHGlobal(image.SizeInBytes());

            var wavelet = new WaveletTransformationController(new Wavelet53RTransformation());

            wavelet.Encode3D(image.ToPointer(), image.ImageInfo.Width, image.ImageInfo.Height, image.ImageInfo.Bands,
                             image.ImageInfo.Width, image.ImageInfo.Height, 0, tempData);


            var budget = (long)(compression * image.SizeInBytes() * 8);

            using (var stream = File.Open(tempPath, FileMode.Create))
            {
                var coder      = new ArithmeticCoder(stream);
                var compressor = new Spiht3DCoder(tempData,
                                                  image.ImageInfo.Width,
                                                  image.ImageInfo.Height,
                                                  image.ImageInfo.Bands);

                compressor.Encode(coder, budget);
            }
            GC.Collect();

            using (var stream = File.Open(tempPath, FileMode.Open))
            {
                var decoder      = new ArithmeticDecoder(stream);
                var decompressor = new Spiht3DDecoder(tempData,
                                                      image.ImageInfo.Width,
                                                      image.ImageInfo.Height,
                                                      image.ImageInfo.Bands);

                decompressor.Decode(decoder, budget);
            }
            GC.Collect();



            wavelet.Decode3D(tempData, image.ImageInfo.Width, image.ImageInfo.Height, image.ImageInfo.Bands,
                             image.ImageInfo.Width, image.ImageInfo.Height, 0, restoredData);

            using (var stream = File.Open(restoredPath, FileMode.Create))
            {
                HyperspectralImage.Save(HyperspectralImage.Load(restoredData, image.ImageInfo), stream);
            }

            Console.WriteLine("Compression 1:{0}. PSNR = {1}", 1 / compression, PSNRCalculator.Calculate(image.ToPointer(), restoredData, image.ImageInfo));
            Console.WriteLine("Compression 1:{0}. MSE = {1}", 1 / compression, PSNRCalculator.CalculateMSE(image.ToPointer(), restoredData, image.ImageInfo));
            sw.Stop();

            Console.WriteLine("{0}:{1} (Ticks: {2})", sw.Elapsed.Seconds, sw.Elapsed.Milliseconds, sw.ElapsedTicks);


            Marshal.FreeHGlobal(tempData);
            Marshal.FreeHGlobal(restoredData);
        }