Convolution filters are usually applied via image processing software, but we can use the same principles to change a grid's influence given a unit's value and its surroundings. In this recipe, we will explore a couple of algorithms to modify a grid using matrix filters.
It is important to have grasped the concept of influence maps before implementing this recipe, so that you can understand the context in which it is applied.
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 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...