Ejemplo n.º 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");
        }
Ejemplo n.º 2
0
        private static void BoxFilter(FileInfo file, string outputFileName)
        {
            Console.WriteLine("***BOX 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 GaussNoise(new Normal(0, 0.25)));
                imageLoader.Save($"{outputFileName}noise{file.Extension}");
                Console.WriteLine($"psnr-noise:     {imageLoader.CalculatePSNR(image):F2}");

                imageLoader.AddBoxFilter(5);
                imageLoader.Save($"{outputFileName}boxfiltered{file.Extension}");
                Console.WriteLine($"psnr-boxfilter: {imageLoader.CalculatePSNR(image):F2}");
            }
        }
Ejemplo n.º 3
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}");
            }
        }
Ejemplo n.º 4
0
        private void PlotGaussFilter()
        {
            var plotGauss = new PlotModel {
                Title = $"Gauss Filter Plot for {fileInfo.Name}"
            };

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

            using (var imageLoader = new ImageLoader())
            {
                imageLoader.Load(fileInfo.FullName);
                Image image = imageLoader.Image;
                Image noise = imageLoader.AddNoise(new GaussNoise(new Normal(0, 0.25))).Image;

                for (var R = 1; R <= 8; R++)
                {
                    var points = new LineSeries
                    {
                        StrokeThickness = 2,
                        MarkerSize      = 4,
                        Title           = $"R = {R}"
                    };
                    points.MarkerType = MarkerType.Circle;

                    for (var sigma = 0.5; sigma <= 3; sigma += 0.5)
                    {
                        imageLoader.Image = noise;

                        imageLoader.AddGaussFilter(R, sigma);

                        double psnr = imageLoader.CalculatePSNR(image);

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

                        imageLoader.Image = image;
                    }

                    plotGauss.Series.Add(points);
                }
            }
            pngExporter.ExportToFile(plotGauss, $"{outputPath}/{fileInfo.Name}/GaussFilterPlot.png");
        }
Ejemplo n.º 5
0
        private void PlotImpulseNoise()
        {
            var plotGauss = new PlotModel {
                Title = $"Impulse Noise Plot for {fileInfo.Name}"
            };

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

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

                for (var p1 = 0.1; p1 <= 0.5; p1 += 0.1)
                {
                    var impulsePoints = new LineSeries
                    {
                        StrokeThickness = 2,
                        MarkerSize      = 4,
                        Title           = $"p1 = {p1}"
                    };
                    impulsePoints.MarkerType = MarkerType.Circle;

                    for (var p2 = 0.0; p2 <= 0.5; p2 += 0.1)
                    {
                        imageLoader.AddNoise(new ImpulseNoise(p1, p2));

                        double psnr = imageLoader.CalculatePSNR(image);

                        impulsePoints.Points.Add(new DataPoint(p2, psnr));

                        imageLoader.Image = image;
                    }

                    plotGauss.Series.Add(impulsePoints);
                }
            }
            pngExporter.ExportToFile(plotGauss, $"{outputPath}/{fileInfo.Name}/ImpulseNoisePlot.png");
        }
Ejemplo n.º 6
0
        private void PlotAdditiveNoise()
        {
            var plotGauss = new PlotModel {
                Title = $"Additive Noise Plot for {fileInfo.Name}"
            };

            plotGauss.Axes.Add(new LinearAxis {
                Title = "Standard Deviation", Position = AxisPosition.Bottom
            });
            plotGauss.Axes.Add(new LinearAxis {
                Title = "PSNR", Position = AxisPosition.Left
            });

            var gaussPoints = new LineSeries
            {
                StrokeThickness = 2,
                MarkerSize      = 4,
                Color           = OxyColors.Red
            };

            gaussPoints.MarkerType = MarkerType.Circle;

            using (var imageLoader = new ImageLoader())
            {
                imageLoader.Load(fileInfo.FullName);
                Image image = imageLoader.Image;
                for (var stddev = 0.0; stddev < 240; stddev += 10)
                {
                    imageLoader.AddNoise(new GaussNoise(new Normal(0, stddev)));

                    double psnr = imageLoader.CalculatePSNR(image);

                    gaussPoints.Points.Add(new DataPoint(stddev, psnr));

                    imageLoader.Image = image;
                }
            }

            plotGauss.Series.Add(gaussPoints);
            pngExporter.ExportToFile(plotGauss, $"{outputPath}/{fileInfo.Name}/AdditiveNoisePlot.png");
        }
Ejemplo n.º 7
0
        void PlotGaussR()
        {
            var plotGauss = new PlotModel {
                Title = $"Gauss R with sigma 2 for {fileInfo.Name}"
            };

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

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

                var points = new LineSeries
                {
                    StrokeThickness = 2,
                    MarkerSize      = 4,
                    Color           = OxyColors.Red
                };

                for (var R = 1; R <= 8; R++)
                {
                    //imageLoader.Image = noise;
                    imageLoader.AddNoise(new GaussNoise(new Normal(0, 35))); // 100 dispersy
                    imageLoader.AddGaussFilter(R, 2);

                    double psnr = imageLoader.CalculatePSNR(image);

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

                    imageLoader.Image = image;
                }
                plotGauss.Series.Add(points);
            }
            pngExporter.ExportToFile(plotGauss, $"{outputPath}/{fileInfo.Name}/GaussFilterPlotR.png");
        }
Ejemplo n.º 8
0
        private static void Noise(FileInfo file)
        {
            Console.WriteLine("***ADDING NOISES***");
            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            var gaussPoints = new LineSeries
            {
                StrokeThickness = 2,
                MarkerSize      = 4,
                Color           = OxyColors.Red
            };

            var impulsePoints = new LineSeries
            {
                StrokeThickness = 2,
                MarkerSize      = 4,
                Color           = OxyColors.Blue
            };

            var psnrGauss   = new List <double>();
            var psnrImpulse = new List <double>();

            using (var imageLoader = new ImageLoader())
            {
                var stddevValues = new List <double>
                {
                    0.025,
                    0.05,
                    0.10,
                    0.25,
                    0.5
                };

                var probValuse = new List <double>
                {
                    0.025,
                    0.05,
                    0.1,
                    0.25,
                    0.5
                };

                imageLoader.Load(file.FullName);
                Image image = imageLoader.Image;

                foreach (double stddev in stddevValues)
                {
                    imageLoader.AddNoise(new GaussNoise(new Normal(0, stddev)));

                    double psnr = imageLoader.CalculatePSNR(image);

                    psnrGauss.Add(psnr);
                    gaussPoints.Points.Add(new DataPoint(stddev, psnr));

                    imageLoader.Image = image;
                }

                foreach (double prob in probValuse)
                {
                    imageLoader.AddNoise(new ImpulseNoise(prob, prob));
                    double psnr = imageLoader.CalculatePSNR(image);

                    psnrImpulse.Add(psnr);
                    impulsePoints.Points.Add(new DataPoint(prob, psnr));
                    imageLoader.Image = image;
                }
            }

            Console.WriteLine("Gauss noise: ");
            foreach (double psnr in psnrGauss)
            {
                Console.Write($"{psnr:F2}; ");
            }

            Console.WriteLine();

            Console.WriteLine("Impulse noise: ");
            foreach (double psnr in psnrImpulse)
            {
                Console.Write($"{psnr:F2}; ");
            }

            Console.WriteLine();

            var pngExporter = new PngExporter {
                Width = 1280, Height = 720, Background = OxyColors.White
            };

            var plotGauss = new PlotModel {
                Title = "Gauss noise plot"
            };

            plotGauss.Series.Add(gaussPoints);
            plotGauss.Series.Add(impulsePoints);
            pngExporter.ExportToFile(plotGauss, $"{OutputPath}/noise_psnr.png");
        }