Image Smoothing

3.8

16 votes
Approved, Basic Programming, Easy
Problem

Smoothing is used to reduce noise within an image or to produce a less pixelated image. You have been given an image G of resolution N x N. Image will be represented as a 2D grid G of size N x N where Gi,j will denote intensity of color in a grayscale image of pixel (i,j).

You have been given a filter mask F of size (2M+1) x (2M+1). Using this filter mask, you have to perform smoothing operation on the G and output the final image NewG. Smoothing operation for any particular pixel (i,j) can be described as:

NewGi,j=p=Mp=Mq=Mq=MGi+p,j+qFp,q

In the above formula, if any pixel (x,y) is situated outside of grid of size N x N, then Gx,y=0.

INPUT:
First line of input will consists of two integers N and M. Next 2M+1 lines will consists of 2M+1 integers denoting filter mask F. (M+1)th integer on (M+2)th line will give the value of F0,0, first integer on second line will give the value of FM,M and last integer on (2M+2)th line will give the value of FM,M. Next N lines will consists of N integers denoting the image G.

OUTPUT:
Output the image NewG obtained by smoothing the image G using filter mask F.

CONSTRAINTS
2N100
1M10
0Gi,j,Fi,j100

Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

Apply the filter mask to calculate the image NewG as shown in the image.

enter image description here

Editor Image

?