← 返回 apple 的题目列表Apply a 2D Box Blur Filter
类型:online_judge
Problem
Given a grayscale image matrix img, implement a 3×3 box blur: each output pixel is the average (floor) of the 3×3 neighborhood.
For simplicity, compute results only for interior pixels (rows 1..H-2, cols 1..W-2). Do not output boundary pixels.
Input
Line 1: two integers H W
Next H lines: W integers per line (pixel intensities)
Output
Print the blurred interior matrix of size (H-2) × (W-2), H-2 lines, each with W-2 integers.
Constraints
3 <= H, W <= 1000
0 <= img[i][j] <= 255
Examples
Input:
3 3
1 1 1
1 1 1
1 1 1
Output:
1
Input:
4 5
0 0 0 0 0
0 9 9 9 0
0 9 9 9 0
0 0 0 0 0
Output:
4 6 4
4 6 4
Example
Input
3 3
1 1 1
1 1 1
1 1 1
Output
1