How to apply a filter kernel
In image processing, to apply such a filter you would iterate over all pixels of the input image and in each step place the filter mask over the image so that its center is located at your current pixel. You then "evaluate" the pixels in the neighborhood that are covered by the mask in some way and write the result back to the current pixel.

For a normal convolution, you multiply each element of the filter with the value of the corresponding pixel, add up the results and write the sum to the current pixel.

Erosion is a morphological operation, and you would implement it (on a binary image) by checking whether all "1" values of your mask lie over "1" pixels in the image. If so, you write a "1" to the current pixel (otherwise a "0").

In both cases, make sure to always read your input pixels from an umodified version of the image (rather than modifying the image in-place).