示例#1
0
        static void Main(string[] args)
        {
            GrayBitmap image    = GrayBitmap.Load("../../images/lena_highres_greyscale_noise.bmp");
            GrayBitmap denoised = new GrayBitmap(image.Width, image.Height);

            ushort[] input  = image.PixelsUShort;
            ushort[] output = new ushort[image.Width * image.Height];

            Stopwatch watch = new Stopwatch();

            watch.Start();

            int window = 3;

            // create an instance of runner
            HybRunner runner = HybRunner.Cuda();
            // wrap a new instance of Program
            dynamic wrapper = runner.Wrap(new Program());

            // run the method on GPU
            wrapper.ParForGPU(output, input, (int)image.Width, (int)image.Height, window);

            watch.Stop();
            string time = String.Format("{0:0.00}", watch.ElapsedMilliseconds * 1.0E-3);

            Console.WriteLine($"Naive GPU time : {time}");
            denoised.PixelsUShort = output;
            denoised.Save("../../output-03-naive-gpu/denoised.bmp");
        }
        static void Main(string[] args)
        {
            GrayBitmap image    = GrayBitmap.Load("../../images/lena_highres_greyscale_noise.bmp");
            GrayBitmap denoised = new GrayBitmap(image.Width, image.Height);

            ushort[] input  = image.PixelsUShort;
            ushort[] output = new ushort[image.Width * image.Height];

            Stopwatch watch = new Stopwatch();

            watch.Start();

            dim3 grid  = new dim3(< gridX >, <gridY>, 1);
            dim3 block = new dim3(< blockX >, <blockY>, 1);

            // create an instance of runner
            HybRunner runner = HybRunner.Cuda();
            // wrap a new instance of Program
            dynamic wrapper = runner.Wrap(new Filter());

            // run the method on GPU
            wrapper.SetDistrib(grid, block).ParForGPU(output, input, (int)image.Width, (int)image.Height);

            watch.Stop();
            string time = String.Format("{0:0.00}", watch.ElapsedMilliseconds * 1.0E-3);

            Console.WriteLine($"Parallel2D GPU time : {time}");
            denoised.PixelsUShort = output;
            denoised.Save("../../output-05-dice-gpu/denoised.bmp");
        }
示例#3
0
        static void Main(string[] args)
        {
            int currentDevice;

            cuda.GetDevice(out currentDevice);
            cudaDeviceProp prop;

            cuda.GetDeviceProperties(out prop, currentDevice);

            GrayBitmap image    = GrayBitmap.Load("../../images/lena_highres_greyscale_noise.bmp");
            GrayBitmap denoised = new GrayBitmap(image.Width, image.Height);

            ushort[] input  = image.PixelsUShort;
            ushort[] output = new ushort[image.Width * image.Height];

            Stopwatch watch = new Stopwatch();

            watch.Start();

            int chunk;

            if ((prop.major >= 6) && (prop.minor == 0))
            {
                chunk = ((int)image.Height + (prop.multiProcessorCount / 2) - 1) / (prop.multiProcessorCount / 2);
            }
            else
            {
                chunk = ((int)image.Height + (prop.multiProcessorCount) - 1) / (prop.multiProcessorCount);
            }

            Console.Out.WriteLine("Chunk size = {0}", chunk);

            dim3 grid  = new dim3(16, ((int)image.Height + chunk - 1) / chunk, 1);
            dim3 block = new dim3(128, 1, 1);

            // create an instance of runner
            HybRunner runner = HybRunner.Cuda();
            // wrap a new instance of Program
            dynamic wrapper = runner.Wrap(new Filter());

            // run the method on GPU
            wrapper.SetDistrib(grid, block).ParForGPU(output, input, (int)image.Width, (int)image.Height, chunk);
            cuda.DeviceSynchronize();

            watch.Stop();
            string time = String.Format("{0:0.00}", watch.ElapsedMilliseconds * 1.0E-3);

            string kernelTime = String.Format("{0:0.00}", runner.LastKernelDuration.ElapsedMilliseconds * 1.0E-3);

            Console.WriteLine($"SweepSort GPU time : {time}");
            Console.WriteLine($"SweepSort GPU -- kernel time : {kernelTime}");
            denoised.PixelsUShort = output;
            denoised.Save("../../output-07-cache-aware-gpu/denoised.bmp");

            cuda.DeviceReset();
        }
示例#4
0
        private void updataImg()
        {
            if (curImage != null)
            {
                preImage = curImage;
                pictureBoxPreImg.Image = preImage.enlargeBmp(1);
            }
            curImage = new GrayBitmap(imgBuf, imgWidth, imgHeight);

            pictureBoxCurImg.Image = curImage.enlargeBmp(1);
        }
        static void Main(string[] args)
        {
            GrayBitmap image    = GrayBitmap.Load("../../images/lena_highres_greyscale_noise.bmp");
            GrayBitmap denoised = new GrayBitmap(image.Width, image.Height);

            ushort[] input  = image.PixelsUShort;
            ushort[] output = new ushort[image.Width * image.Height];

            Stopwatch watch = new Stopwatch();

            watch.Start();

            int window = 3;
示例#6
0
        private void Form1_Load(object sender, EventArgs e)
        {
            backgroundWorker.RunWorkerAsync();

            byte[] bytes = new byte[140 * 80];

            int  k   = 0;
            byte val = 0;

            for (int i = 0; i < 140 * 80; i++)
            {
                bytes[k++] = val++;
            }

            curImage = new GrayBitmap(bytes, 140, 80);

            //pictureBoxCurImg.Image = curImage.enlargeBmp(3);

            //grayBmp.bmp.Save("test.png", System.Drawing.Imaging.ImageFormat.Png);
        }
示例#7
0
        private void buttonImgLoadPre_Click(object sender, EventArgs e)
        {
            OpenFileDialog opndlg = new OpenFileDialog();

            opndlg.Filter   = "所有文件|*.bmp;*.jpg";
            opndlg.Title    = "打开图形文件";
            opndlg.ShowHelp = true;
            if (opndlg.ShowDialog() == DialogResult.OK)
            {
                string curFileName = opndlg.FileName;
                try
                {
                    Bitmap curBitmap = (Bitmap)Image.FromFile(curFileName);
                    preImage = new GrayBitmap(curBitmap);
                    pictureBoxPreImg.Image = preImage.enlargeBmp(1);
                }
                catch (Exception exp)
                {
                    MessageBox.Show(exp.Message);
                }
            }
        }
示例#8
0
        static void Main(string[] args)
        {
            GrayBitmap image    = GrayBitmap.Load("../../images/lena_highres_greyscale_noise.bmp");
            GrayBitmap denoised = new GrayBitmap(image.Width, image.Height);

            ushort[] input  = image.PixelsUShort;
            ushort[] output = new ushort[image.Width * image.Height];

            int window = 3;

            Stopwatch watch = new Stopwatch();

            watch.Start();

            NaiveCsharp(output, input, (int)image.Width, (int)image.Height, window);

            watch.Stop();
            string time = String.Format("{0:0.00}", watch.ElapsedMilliseconds * 1.0E-3);

            Console.WriteLine($"Parallel.For time : {time}");
            denoised.PixelsUShort = output;
            denoised.Save("../../output-02-parfor/denoised.bmp");
        }