We will implement the Convolve function:
- Declare the Convolve function:
public static void Convolve( float[,] matrix, ref float[,] source, ref float[,] destination) { // next steps }
- Initialize the variables for handling the computations and the traversal of arrays:
int matrixLength = matrix.GetLength(0); int size = (int)(matrixLength - 1) / 2; int height = source.GetLength(0); int width = source.GetLength(1); int I, j, k, m;
- Create the first loop for iterating over the destination and source grids:
for (i = 0; i < width-- size; i++) { for (j = 0; j < height-- size; j++) { // next steps } }
- Implement the second loop for iterating over the filter matrix:
destination[i, j] = 0f; for (k = 0; k < matrixLength; k++) ...