Bort Dawson

Bort Dawson

  • NA
  • 1
  • 2.1k

Doing Image Processing in C# with Pointers?

Sep 23 2012 5:12 AM

Hello All,

I am writing an image processing application in C# that needs to be speed optimized for faster performance.

I have been told that using Unsafe Code together with Pointers can speed my algorithm up significantly. Unfortunately, I have no experience with Pointers at all.

How can I make the following example code work with Pointers? (The example multiplies a 640 x 480 pixel images' pixel values by 2, and copies those new values into another 640 x 480 image)

Example:

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

            double[,] Redmap = new double[640, 480];
            double[,] Greenmap = new double[640, 480];
            double[,] Bluemap = new double[640, 480];


            double[,] Redmap2 = new double[640, 480];
            double[,] Greenmap2 = new double[640, 480];
            double[,] Bluemap2 = new double[640, 480];



            for (int y = 0; y < 480; y++)
                    {

                for (int x = 0; x < 640; x++)
                        {
                   
                    Redmap2[x, y] = Redmap[x, y] * 2;

                    Greenmap2[x, y] = Greenmap[x, y] * 2;
    
                    Bluemap2[x, y] = Bluemap[x, y] * 2;

                        }
                  }

?

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Thanks in advance for any help provided!


Answers (1)