コード例 #1
0
        public static void ApplyAveragingFilterAndSave(
            string sourceFilePath, byte[,] sourceImage, int filterSize)
        {
            byte[,] resultImage = ImageFiltering.ApplyAveragingFilter(sourceImage, filterSize);
            string newFilePath = ProbA2.NewFilePath(sourceFilePath, $"AveragingFilter{filterSize}");

            Utility.SaveGrayscaleImage(resultImage, newFilePath);

            Console.WriteLine($"Averaging filter (size: {filterSize}) " +
                              $"applied and saved to \'{newFilePath}\'");
        }
コード例 #2
0
        public static byte[,] AddRandomNoiseAndSave(
            string sourceFilePath, byte[,] sourceImage, double noiseLevel)
        {
            byte[,] resultImage = Utility.AddRandomNoise(sourceImage, new Random(), noiseLevel);
            string newFilePath = ProbA2.NewFilePath(
                sourceFilePath, $"RandomNoise{noiseLevel}");

            Utility.SaveGrayscaleImage(resultImage, newFilePath);

            Console.WriteLine($"Random noise (level: {noiseLevel}) added " +
                              $"and saved to \'{newFilePath}\'");

            return(resultImage);
        }
コード例 #3
0
        public static byte[,] ApplyBilateralFilterAndSave(
            string sourceFilePath, byte[,] sourceImage, int filterSize,
            double sigma1, double sigma2, int times)
        {
            byte[,] resultImage = ImageFiltering.ApplyBilateralFilter(
                sourceImage, filterSize, sigma1, sigma2);
            string newFilePath = ProbA2.NewFilePath(
                sourceFilePath, $"BilateralFilter{filterSize}-{sigma1}-{sigma2}-{times}");

            Utility.SaveGrayscaleImage(resultImage, newFilePath);

            Console.WriteLine($"Bilateral filter (size: {filterSize}) " +
                              $"applied and saved to \'{newFilePath}\'");

            return(resultImage);
        }
コード例 #4
0
        public static void Main(string[] args)
        {
            Console.Write("Input image file name: ");
            string fileName = Console.ReadLine();

            byte[,] noiseImage = Utility.LoadGrayscaleImage(fileName);
            int imageWidth  = noiseImage.GetLength(0);
            int imageHeight = noiseImage.GetLength(1);

            /*
             * byte[,] noiseImage = ProbA2.AddShotNoiseAndSave(
             *  fileName, sourceImage, (int)(imageWidth * imageHeight * 0.05), 255.0);
             * byte[,] noiseImage = ProbA2.AddRandomNoiseAndSave(fileName, sourceImage, 16.0);
             */

            ProbA2.ApplyAveragingFilterAndSave(fileName, noiseImage, 5);
            ProbA2.ApplyMedianFilterAndSave(fileName, noiseImage, 5);

            byte[,] resultImage = ProbA2.ApplyBilateralFilterAndSave(
                fileName, noiseImage, 5, 5.0, 5.0, 1);
            resultImage = ProbA2.ApplyBilateralFilterAndSave(
                fileName, resultImage, 5, 5.0, 5.0, 2);
            resultImage = ProbA2.ApplyBilateralFilterAndSave(
                fileName, resultImage, 5, 5.0, 5.0, 3);

            resultImage = ProbA2.ApplyBilateralFilterAndSave(
                fileName, noiseImage, 5, 10.0, 10.0, 1);
            resultImage = ProbA2.ApplyBilateralFilterAndSave(
                fileName, resultImage, 5, 10.0, 10.0, 2);
            resultImage = ProbA2.ApplyBilateralFilterAndSave(
                fileName, resultImage, 5, 10.0, 10.0, 3);

            resultImage = ProbA2.ApplyBilateralFilterAndSave(
                fileName, noiseImage, 5, 15.0, 15.0, 1);
            resultImage = ProbA2.ApplyBilateralFilterAndSave(
                fileName, resultImage, 5, 15.0, 15.0, 2);
            resultImage = ProbA2.ApplyBilateralFilterAndSave(
                fileName, resultImage, 5, 15.0, 15.0, 3);

            Console.ReadKey();
        }