private static void convolve(float[,] image, float[,] temp, float[] kernel)
{
int width = image.GetLength(1);
int height = image.GetLength(0);
int radius = kernel.Length / 2;
unsafe
{
fixed (float* ptrImage = image, ptrTemp = temp)
{
float* src = ptrImage + radius;
float* tmp = ptrTemp + radius;
for (int y = 0; y < height; y++)
{
for (int x = radius; x < width - radius; x++, src++, tmp++)
{
float v = 0;
for (int k = 0; k < kernel.Length; k++)
v += src[k - radius] * kernel[k];
*tmp = v;
}
src += 2 * radius;
tmp += 2 * radius;
}
for (int x = 0; x < width; x++)
{
for (int y = radius; y < height - radius; y++)
{
src = ptrImage + y * width + x;
tmp = ptrTemp + y * width + x;
float v = 0;
for (int k = 0; k < kernel.Length; k++)
v += tmp[width * (k - radius)] * kernel[k];
*src = v;
}
}
}
}
}