13: Image Fuzzy processing, 13 image fuzzy
13. Image Fuzzy Processing
- View
- Submit
- Statistics
- Question
-
Total time limit:
-
1000 ms
-
Memory limit:
-
65536kB
-
Description
-
For the gray value of each pixel of an image in n rows and m columns, you must use the following method to blur it:
1. The gray value of the outermost pixel remains unchanged;
2. The new gray value of each pixel in the middle is the average of the original gray value of the pixel and its upper and lower left and right adjacent four pixels (rounded to the nearest integer ).
-
Input
-
The first line contains two integers n and m, indicating that the image contains the number of rows and columns of pixels. 1 <= n <= 100, 1 <= m <=.
In the next n rows, each row has m integers, indicating the gray scale of each pixel of the image. Two Adjacent integers are separated by a single space. Each element ranges from 0 ~ In the range of 255.
-
Output
-
N rows, m integers in each row, are the blurred images. Two Adjacent integers are separated by a single space.
-
Sample Input
-
4 5100 0 100 0 5050 100 200 0 050 50 100 100 200100 100 50 50 100
-
Sample output
-
100 0 100 0 5050 80 100 60 050 80 100 90 200100 100 50 50 100
#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>using namespace std;int a[10001][10001];int b[10001][10001];int main(){ int n,m; cin>>n>>m; for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { cin>>a[i][j]; b[i][j]=a[i][j]; } } for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { if(i==1||i==n||j==1||j==m) { continue; } else { double r=((double)a[i][j]+a[i-1][j]+a[i+1][j]+a[i][j-1]+a[i][j+1])/5; b[i][j]=round(r); } } } for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) cout<<b[i][j]<<" "; cout<<endl; } return 0;}