Poj3999 kind of a blur, Gaussian deyuan

Source: Internet
Author: User
Kind of a blur
Time limit:1000 ms   Memory limit:65536 K
Total submissions:642   Accepted:137

Description

Image Blurring occurs when the object being captured is out of the camera's focus. the top two figures on the right are an example of an image and its blurred version. restoring the original image given only the blurred version is one of the most interesting topics in image processing. this process is called deblurring, which will be your task for this problem.

In this problem, all images are in gray-scale (no colours ). images are represented as a 2 dimen1_matrix of real numbers, where each cell corresponds to the brightness of the corresponding pixel. although not mathematically accurate, one way to describe a blurred image is through averaging all the pixels that are within (less than or equal) A certain Manhattan distance (the Manhattan distance (sometimes called the taxicab distance) between two points is the sum of the (absolute) difference of their coordinates. the grid on the lower right into strates the Manhattan distances from the grayed cell .) from each pixel (including the pixel itself ). here's an example of how to calculate the blurring of a 3*3 image with a blurring distance of 1:

Given the blurred version of an image, we are interested in reconstructing the original version assuming that the image was blurred as explained above.

Input

Input consists of several test cases. each case is specified on H + 1 lines. the first line specifies three non negative integers specifying the width W, the height H of the blurred image and the blurring distance d respectively where (1 ≤ W, h ≤ 10) and (D ≤ min (W/2, H/2 )). the remaining H lines specify the gray-level of each pixel in the blurred image. each line specifies W non-negative real numbers given up to the 2nd decimal place. the value of all the given real numbers will be less than 100.
Zero or more lines (made entirely of white spaces) may appear between cases. The last line of the input file consists of three zeros.

Output

For each test case, print a w * H matrix of real numbers specifying the deblurred version of the image. each element in the matrix shocould be approximated to 2 decimal places and right justified in a field of width 8. separate the output of each two consecutive test cases by an empty line. do not print an empty line after the last test case. it is guaranteed that there is exactly one unique solution for every test case.

Sample Input

2 2 11 11 13 3 119 14 2012 15 1813 14 164 4 214 15 14 1514 15 14 1514 15 14 1514 15 14 150 0 0

Sample output

    1.00    1.00    1.00    1.00    2.00   30.00   17.00   25.00    7.00   13.00   14.00    0.00   35.00    1.00   27.00    2.00   28.00   21.00   12.00   17.00    8.00   21.00   12.00   17.00    8.00    1.00   27.00    2.00   28.00




#include <cmath>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <set>#include <map>#include <string>#include <stack>#include <queue>#include <vector>#define for0(a,b) for(a=0;a<b;++a)#define for1(a,b) for(a=1;a<=b;++a)#define foru(i,a,b) for(i=a;i<=b;++i)#define ford(i,a,b) for(i=a;i>=b;--i)using namespace std;typedef double db;typedef long long ll;const db eps = 1e-8;const int inf = 1e9;const int N = 105;db a[N][N], g[N][N], x[N];int pos[N][N];int n, m, d, cnt;int dis(int x1, int y1, int x2, int y2){    return abs(x1-x2) + abs(y1-y2);}void Gauss(){    db tmp, big;    for(int i=0; i<cnt; ++i) {        int r, big = 0;        for(int j=i; j<cnt; ++j) {            if(abs(g[j][i])>big) {                big = abs(g[j][i]);                r = j;            }        }        if(r != i) {            for (int j = 0; j <= cnt; j++) {                swap(g[i][j], g[r][j]);            }        }        for(int j=i+1; j<cnt; ++j) {            if(g[j][i]) {                tmp = g[j][i]/g[i][i];                for(int k=i; k<=cnt; ++k) {                    g[j][k] -= tmp*g[i][k];                }            }        }        for(int i=cnt-1; i>=0; --i) {            tmp = 0;            for(int j=i+1; j<cnt; ++j) {                tmp += g[i][j]*x[j];            }            x[i] = (g[i][cnt] - tmp)/g[i][i];        }    }}int main(){#ifndef ONLINE_JUDGE    freopen("in.cpp", "r", stdin);    freopen("out.cpp","w", stdout);#endif // ONLINE_JUDGE    bool first = 1;    while(~scanf("%d%d%d", &m, &n, &d)) {        if(m==0&&n==0&&d==0) break;        if(!first) puts("");        else first = 0;        cnt = 0;        for(int i=0; i<n; ++i) {            for(int j=0; j<m; ++j) {                scanf("%lf", &a[i][j]);                pos[i][j] = cnt++;            }        }        memset(g, 0, sizeof g );        for(int i=0; i<n; ++i) {            for(int j=0; j<m; ++j) {                for(int k=0; k<n; ++k) {                    for(int l=0; l<m; ++l) {                        if(dis(i,j,k,l)<=d) {                            g[pos[i][j]][pos[k][l]] = 1;                            g[pos[i][j]][cnt] += a[i][j];                        }                    }                }            }        }        Gauss();        for(int i=0; i<n; ++i) {            for(int j=0; j<m; ++j) {                printf("%8.2lf", x[i*m + j]);            }            printf("\n");        }    }    return 0;}




Poj3999 kind of a blur, Gaussian deyuan

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.