class Solution {
public int conv(int i, int j, int[][] img) {
int M = img.length, N = img[0].length;
int numerator = 0, denominator = 0;
for (int row = i-1; row <= i+1; row++) {
for (int col = j-1; col <= j+1; col++) {
if (0 <= row && row < M && 0 <= col && col < N) {
numerator += img[row][col];
denominator++;
}
}
}
return numerator / denominator;
}
public int[][] imageSmoother(int[][] img) {
int M = img.length, N = img[0].length;
int[][] ans = new int[M][N];
for (int i = 0; i < M; i++) {
for (int j = 0; j < N; j++) {
ans[i][j] = conv(i, j, img);
}
}
return ans;
}
}