Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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;
                }
            }
        }