static void ApplyWavelet()
        {
            int times = 7;

            string[] images = Directory.GetFiles(@"..\..\..\TestHaarCSharp\Resources_Noisy\", "*", SearchOption.AllDirectories);
            Parallel.ForEach(images, (i) =>
            {
                Bitmap initial = new Bitmap(Image.FromFile(i));

                //var res = AddNoise(initial, 50);
                //res.Save($@"..\..\..\TestHaarCSharp\Resources_noisy\{Path.GetFileName(i)}", res.RawFormat);

                Bitmap forward = new Bitmap(initial);

                var channels       = ColorChannels.CreateColorChannels(initial.Width, initial.Height);
                var transform      = WaveletTransform.CreateTransform(true, times);
                var imageProcessor = new ImageProcessor(channels, transform);
                imageProcessor.ApplyTransform(forward);

                string newPath = Path.Combine(@"..\..\..\TestHaarCSharp\Forward_Noisy", Path.GetFileName(i));
                string dirName = Path.GetDirectoryName(newPath);
                if (!Directory.Exists(dirName))
                {
                    Directory.CreateDirectory(dirName);
                }
                forward.Save(newPath, initial.RawFormat);


                Bitmap inverse = new Bitmap(forward);
                transform      = WaveletTransform.CreateTransform(false, times);
                imageProcessor = new ImageProcessor(channels, transform);
                imageProcessor.ApplyTransform(inverse);

                var rmse = GetRMSE(initial, inverse);

                newPath = Path.Combine(@"..\..\..\TestHaarCSharp\Inverse_Noisy",
                                       $"{Path.GetFileNameWithoutExtension(i)}_{rmse.ToString("#.##")}{Path.GetExtension(i)}");
                dirName = Path.GetDirectoryName(newPath);
                if (!Directory.Exists(dirName))
                {
                    Directory.CreateDirectory(dirName);
                }
                inverse.Save(newPath, inverse.RawFormat);
            });
        }
Exemple #2
0
        private Bitmap ApplyHaarTransform(bool forward, bool safe, int iterations, Bitmap bmp)
        {
            var maxScale = WaveletTransform.GetMaxScale(bmp.Width, bmp.Height);

            if (iterations < 1 || iterations > maxScale)
            {
                MessageBox.Show(string.Format("Iteration must be Integer from 1 to {0}", maxScale));
                return(new Bitmap(bmp.Width, bmp.Height));
            }

            var channels = ColorChannels.CreateColorChannels(safe, bmp.Width, bmp.Height);

            var transform = WaveletTransform.CreateTransform(forward, iterations);

            var imageProcessor = new ImageProcessor(channels, transform);

            imageProcessor.ApplyTransform(bmp);
            return(bmp);
        }