在C#中创建任意数量的指针

时间:2013-10-22 18:39:34

标签: c# visual-studio-2010 image-processing

我想实现一个n * n平均滤波器。为此,我想创建n * n个指针,指向原始图像的n * n方形区域,并将每个组件的值存储在该方块的每个像素中。我想给每个指针指定一个不同的名称,也就是说,我想创建从dataPtrOrigin_aux0开始到dataPtrOrigin_aux(n * n-1)结束的指针。我有以下代码:

`internal static void nxn_average(Image img,Image imgUndo){

    unsafe
        {

            MIplImage m = img.MIplImage;
            MIplImage mUndo = imgUndo.MIplImage;
            byte* dataPtrFinal = (byte*)m.imageData.ToPointer();
            byte* dataPtrUndo = (byte*)mUndo.imageData.ToPointer();


            int width = img.Width;
            int height = img.Height;
            int nChan = m.nChannels;
            int padding = m.widthStep - m.nChannels * m.width;

            int b_sum, g_sum, r_sum;
            int b_average, g_average, r_average;
            int x, y, i, j, k;
            int counter = 0;
            int n = 5;

            string[] ptr_names_arr = new string[n*n];

            //create the names of the n*n pointers

            for (i = 0; i < n * n; i++)
            {

                char ptr_nr = (char)i;

                string ptr_name = String.Concat("dataPtrOrigin_aux", ptr_nr);

                ptr_names_arr[i] = ptr_name;

            }

            for (x = 0; x < width; x++)
            {
                for (y = 0; y < height; y++)
                {


                    for (j = 0; j < n; j++)
                    {
                        for (k = 0; k < n; k++)
                        {


                            string ptr_aux = ptr_names_arr[counter];
                            counter++;

                            byte*  ptr_aux = (byte*)(dataPtrUndo + (y - (int)Math.Floor(n/2) + j) * m.widthStep + (x - (int)Math.Floor(n/2) + k) * m.nChannels);


                        }
                    }
                }
            }

        }
    }`

虽然我尝试使用该行时出错:

byte*  ptr_aux = (byte*)(dataPtrUndo + (y - (int)Math.Floor(n/2) + j) * m.widthStep + (x - (int)Math.Floor(n/2) + k) * m.nChannels);

还有其他方法可以创建任意数量的指针吗?

0 个答案:

没有答案