Пример #1
0
        private void PlotMedianFilter()
        {
            var plotMedian = new PlotModel {
                Title = $"Median Filter Plot for {fileInfo.Name}"
            };

            plotMedian.Axes.Add(new LinearAxis {
                Title = "R", Position = AxisPosition.Bottom
            });
            plotMedian.Axes.Add(new LinearAxis {
                Title = "PSNR", Position = AxisPosition.Left
            });

            var probValue = new List <double>
            {
                0.025,
                0.050,
                0.125,
                0.250
            };

            using (var imageLoader = new ImageLoader())
            {
                imageLoader.Load(fileInfo.FullName);
                Image image = imageLoader.Image;

                foreach (var value in probValue)
                {
                    var points = new LineSeries
                    {
                        StrokeThickness = 2,
                        MarkerSize      = 4,
                        Title           = $"{value * 2 * 100} %"
                    };
                    points.MarkerType = MarkerType.Circle;

                    for (var R = 1; R <= 5; R++)
                    {
                        imageLoader.AddNoise(new ImpulseNoise(value, value));
                        imageLoader.AddMedianFilter(R);

                        double psnr = imageLoader.CalculatePSNR(image);

                        points.Points.Add(new DataPoint(R, psnr));

                        imageLoader.Image = image;
                    }

                    plotMedian.Series.Add(points);
                }
            }
            pngExporter.ExportToFile(plotMedian, $"{outputPath}/{fileInfo.Name}/MedianFilterPlot.png");
        }
Пример #2
0
        private static void MedianFilter(FileInfo file, string outputFileName)
        {
            Console.WriteLine("***MEDIAN FILTER***");

            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            using (var imageLoader = new ImageLoader())
            {
                imageLoader.Load(file.FullName);
                Image image = imageLoader.Image;
                imageLoader.AddNoise(new ImpulseNoise(0.125, 0.125));
                imageLoader.Save($"{outputFileName}impulsenoise{file.Extension}");
                Console.WriteLine($"psnr-noise:     {imageLoader.CalculatePSNR(image):F2}");

                imageLoader.AddMedianFilter(2);
                imageLoader.Save($"{outputFileName}medianfiltered{file.Extension}");
                Console.WriteLine($"psnr-medianfilter: {imageLoader.CalculatePSNR(image):F2}");
            }
        }