private RgbImage Convolve(double[][] kernel)
        {
            RgbImage image        = new RgbImage(this.height, this.width);
            int      kernel_width = kernel.Length / 2;
            int      kernel_sum   = 1;

            for (int row_num = 0; row_num < height; row_num++)
            {
                for (int cell_num = 0; cell_num < width; cell_num++)
                {
                    for (int chanel_num = 0; chanel_num < 3; chanel_num++)
                    {
                        int base_row = row_num - kernel_width,
                            base_col = cell_num - kernel_width,
                            sum      = 0;

                        for (int row_offset = 0; row_offset < kernel.Length; row_offset++)
                        {
                            for (int col_offset = 0; col_offset < kernel[0].Length; col_offset++)
                            {
                                int row     = base_row + row_offset,
                                    col     = base_col + col_offset,
                                    element = this.GetElement(row, col, chanel_num);
                                sum += (int)(element * kernel[row_offset][col_offset]);
                            }
                        }

                        image.image[row_num, cell_num, chanel_num] = sum / kernel_sum;
                    }
                }
            }

            return(image);
        }
示例#2
0
        static void Main(string[] args)
        {
            try
            {
                string inputFile = args[0],
                       height = args[1],
                       width = args[2],
                       outputFile = args[3],
                       benchmarkFile = args[4];

                Stopwatch sw = Stopwatch.StartNew();
                for (var _ = 0; _ < 100; _++)
                {
                    RgbImage image = new RgbImage(inputFile, Int32.Parse(height), Int32.Parse(width));
                    image.Blur().SaveToFile(outputFile);
                }
                sw.Stop();
                File.AppendAllText(benchmarkFile, "C#: " + (sw.Elapsed.TotalSeconds / 100.0).ToString() + "s." + Environment.NewLine);
            }
            catch (IndexOutOfRangeException)
            {
                Console.Write(Program.docString);
            }
        }
        static void Main(string[] args)
        {
            try
            {
                string inputFile     = args[0],
                       height        = args[1],
                       width         = args[2],
                       outputFile    = args[3],
                       benchmarkFile = args[4];

                Stopwatch sw = Stopwatch.StartNew();
                for (var _ = 0; _ < 100; _++)
                {
                    RgbImage image = new RgbImage(inputFile, Int32.Parse(height), Int32.Parse(width));
                    image.Blur().SaveToFile(outputFile);
                }
                sw.Stop();
                File.AppendAllText(benchmarkFile, "C#: " + (sw.Elapsed.TotalSeconds / 100.0).ToString() + "s." + Environment.NewLine);
            }
            catch (IndexOutOfRangeException)
            {
                Console.Write(Program.docString);
            }
        }
示例#4
0
        private RgbImage Convolve(double[][] kernel)
        {
            RgbImage image = new RgbImage(this.height, this.width);
            int kernel_width = kernel.Length / 2;
            int kernel_sum = 1;

            for (int row_num = 0; row_num < height; row_num++)
                    for (int cell_num = 0; cell_num < width; cell_num++)
                        for (int chanel_num = 0; chanel_num < 3; chanel_num++)
                        {
                            int base_row = row_num - kernel_width,
                                base_col = cell_num - kernel_width,
                                sum = 0;

                            for (int row_offset = 0; row_offset < kernel.Length; row_offset++)
                                for (int col_offset = 0; col_offset < kernel[0].Length; col_offset++)
                                {
                                    int row = base_row + row_offset,
                                        col = base_col + col_offset,
                                        element = this.GetElement(row, col, chanel_num);
                                    sum += (int)(element * kernel[row_offset][col_offset]);
                                }

                            image.image[row_num, cell_num, chanel_num] = sum / kernel_sum;
                        }

            return image;
        }