13: Image Fuzzy processing, 13 image fuzzy

Source: Internet
Author: User

13: Image Fuzzy processing, 13 image fuzzy
13. Image Fuzzy Processing

  • View
  • Submit
  • Statistics
  • Question
Total time limit:
1000 ms
Memory limit:

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 ).

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.
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;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.