I need to take in user input which outputs a matrix of integers, then that matrix must be "smoothed" using a means filter to output a new matrix. Right now I have it to where I can take in the user input and output a matrix using randomly generated numbers, but i'm stumped as to how to accomplish this. PLEASE HELP!!

Below is the original instructions:

Write a program that will take as input an image, represented as a 2D array of pixel values (for simplicity, each pixel can be represented by an integer). Output the resulting smoothened image by applying the mean filter to every pixel in the array. Note that some pixels do not have 4 neighbors (for instance, pixels in the corners have only 2 neighbors; pixels in the top row and not in the corners have only 3 neighbors, and so on). Your program must take this into account and always use all available values but never use a non-valid (out of array) value.