private static void TwoDotGrad(FileInfo file, string outputFileName) { double[] a = { 0, 65, 180, 255 }; double[] b = { 0, 40, 210, 255 }; var f = MathNet.Numerics.Interpolate.Linear(a, b); using (var imageLoader = new ImageLoader()) { imageLoader.Load(file.FullName); imageLoader.AddNoise(new GaussNoise(new Normal(0.0001, 0.0001))); Bitmap image = (Bitmap)imageLoader.Image; imageLoader.PlotHistogram("before", OutputPath, file); int height = image.Height; int width = image.Width; for (var y = 0; y < height; y++) { for (var x = 0; x < width; x++) { double color = f.Interpolate(image.GetPixel(x, y).R); Color destinationColor = Color.FromArgb( Convert.ToByte(color.Clamp(0, 255)), Convert.ToByte(color.Clamp(0, 255)), Convert.ToByte(color.Clamp(0, 255))); image.SetPixel(x, y, destinationColor); } } imageLoader.Image = image; imageLoader.Save($"{outputFileName}_gradation_{file.Extension}"); imageLoader.PlotHistogram("after", OutputPath, file); } }
private static void LaplacianFilter(FileInfo file, string outputFileName) { Console.WriteLine("***LAPLACIAN FILTER***"); if (file == null) { throw new ArgumentNullException(nameof(file)); } double[] alphas = { 0, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6 }; using (var imageLoader = new ImageLoader()) { imageLoader.Load(file.FullName); imageLoader.AddNoise(new GaussNoise(new Normal(0.0001, 0.0001))); Image I = imageLoader.Image; Console.WriteLine($"Avg luma of src: {imageLoader.CalculateAvgLuminocity()}"); imageLoader.PlotHistogram("src", OutputPath, file); foreach (var alpha in alphas) { if (alpha == 0) { double[,] I1 = imageLoader.AddLaplacianFilterAlpha0(); //imageLoader.Save($"{outputFileName}_I1_laplacianfiltered{file.Extension}"); //Console.WriteLine($"Avg luma of I1: {imageLoader.CalculateAvgLuminocity()}"); //imageLoader.PlotHistogram("I1", OutputPath, file); imageLoader.Add128(I1); imageLoader.Save($"{outputFileName}_I1+128_laplacianfiltered{file.Extension}"); Console.WriteLine($"Avg luma of I1 + 128: {imageLoader.CalculateAvgLuminocity()}"); imageLoader.PlotHistogram("I1+128", OutputPath, file); imageLoader.Image = I; imageLoader.AddImage(I, I1); imageLoader.Save($"{outputFileName}_I2_laplacianfiltered{file.Extension}"); Console.WriteLine($"Avg luma of I2: {imageLoader.CalculateAvgLuminocity()}"); imageLoader.PlotHistogram("I2", OutputPath, file); } else { imageLoader.AddLaplacianFilter(alpha); imageLoader.Save($"{outputFileName}laplacianfiltered_(alpha={alpha}){file.Extension}"); Console.WriteLine($"Avg luma of alpha = {alpha}: {imageLoader.CalculateAvgLuminocity()}"); imageLoader.PlotHistogram($"alpha={alpha}", OutputPath, file); } imageLoader.Image = I; } } }
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"); }
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"); }
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"); }
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"); }
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"); }
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}"); } }
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}"); } }
private static void SobelFilter(FileInfo file, string outputFileName) { Console.WriteLine("***SOBEL FILTER***"); if (file == null) { throw new ArgumentNullException(nameof(file)); } using (var imageLoader = new ImageLoader()) { imageLoader.Load(file.FullName); imageLoader.AddNoise(new GaussNoise(new Normal(0.0001, 0.0001))); Image I = imageLoader.Image; //Image Gh = imageLoader.AddSobelFilter("H").Image; //imageLoader.Save($"{outputFileName}_GH_sobel{file.Extension}"); //imageLoader.Image = I; //Image Gv = imageLoader.AddSobelFilter("V").Image; //imageLoader.Save($"{outputFileName}_GV_sobel{file.Extension}"); double[,] Gv = imageLoader.GetSobelFilterDouble("V"); double[,] Gh = imageLoader.GetSobelFilterDouble("H"); Image ColorMap = Filters.SobelFilter.GetColorMap(Gv, Gh); imageLoader.Image = ColorMap; imageLoader.Save($"{outputFileName}_sobel_ColorMap_{file.Extension}"); for (int thr = 15; thr < 200; thr += 10) { Image BinaryCard = Filters.SobelFilter.GetBinaryCard(thr, Gv, Gh); imageLoader.Image = BinaryCard; imageLoader.Save($"{outputFileName}_sobel_BinaryCard_(thr={thr}){file.Extension}"); } } }
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"); }