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 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 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}"); } } }