我想实现一个* n 平均滤波器。为此,我想创建 n*n 指针指向原始图像的一个 *n 正方形区域,并将每个分量的值存储在该正方形的每个像素中。我想为每个指针指定一个不同的名称,也就是说,我想创建从 dataPtrOrigin_aux0 开始到 dataPtrOrigin_aux(n*n-1) 结束的指针。我有以下代码:
`内部静态无效nxn_average(图像img,图像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);
有没有其他方法可以创建任意数量的指针?