Easy solution 91.7%
Iterate from [0, 0] to [m - 2, n - 2] and record sum and count.\n\nclass Solution {\n    public int[][] resultGrid(int[][] image, int threshold) {\n        int 
Iterate from [0, 0] to [m - 2, n - 2] and record sum and count.\n```\nclass Solution {\n    public int[][] resultGrid(int[][] image, int threshold) {\n        int m = image.length, n = image[0].length;\n        int[][] sum = new int[m][n];\n        int[][] count = new int[m][n];\n        for (int i = 0; i < m - 2; i++) {\n            for (int j = 0; j < n - 2; j++) {\n                recordIntensity(image, threshold, i, j, sum, count);\n            }\n        }\n        for (int i = 0; i < m; i++) {\n            for (int j = 0; j < n; j++) {\n                if (count[i][j] > 0) {\n                    image[i][j] = sum[i][j] / count[i][j];\n                }\n            }\n        }\n        return image;\n    }\n\n    public void recordIntensity(int[][] image, int threshold, \n        int row, int col, int[][] sum, int[][] count) {\n        int total = 0;\n        for (int i = row; i <= row + 2; i++) {\n            for (int j = col; j <= col + 2; j++) {\n                if (i + 1 <= row + 2 && Math.abs(image[i + 1][j] - image[i][j]) > threshold) {\n                    return;\n                }\n                if (j + 1 <= col + 2 && Math.abs(image[i][j + 1] - image[i][j]) > threshold) {\n                    return;\n                }\n                total += image[i][j];\n            }\n        }\n        int avg = total / 9;\n        for (int i = row; i <= row + 2; i++) {\n            for (int j = col; j <= col + 2; j++) {\n                sum[i][j] += avg;\n                count[i][j]++;\n            }\n        }\n    }\n}\n```
['Java']