#B2108. Image Blur using Cross Averaging

    ID: 11190 Type: Default 1000ms 256MiB

Image Blur using Cross Averaging

Image Blur using Cross Averaging

Given an image represented as a matrix with n rows and m columns, where each element denotes the grayscale value of a pixel, perform a blurring operation as described below:

  1. The pixels on the outer border remain unchanged.
  2. For each inner pixel (not on the border), compute the new grayscale value as the average of the pixel and its four adjacent neighbors (up, down, left, right). Formally, for an inner pixel at position \((i,j)\), the new value is $$\text{new}_{i,j}=\operatorname{round}\Bigl(\frac{a_{i,j}+a_{i-1,j}+a_{i+1,j}+a_{i,j-1}+a_{i,j+1}}{5}\Bigr)$$ where \(\operatorname{round}\Bigl(\cdot\Bigr)\) denotes rounding to the nearest integer.

Output the modified image after blurring.

inputFormat

The first line contains two integers (n) and (m) ((n,m \ge 3)), representing the number of rows and columns in the image. Each of the following (n) lines contains (m) space-separated integers, where each integer represents the grayscale value of a pixel.

outputFormat

Output the transformed image as (n) lines, each containing (m) space-separated integers. The border pixels remain unchanged, and each inner pixel is replaced with the average (rounded to the nearest integer) of itself and its four neighbors.

sample

3 3
1 2 3
4 5 6
7 8 9
1 2 3

4 5 6 7 8 9

</p>