zoukankan      html  css  js  c++  java
  • hdu 3359 Kind of a Blur 高斯消元

    Kind of a Blur

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

    Problem 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 grey-scale (no colours). Images are represented as a 2 dimensional 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 to) a certain Manhattan distance?from each pixel (including the pixel itself ). Here's an example of how to calculate the blurring of a 3x3 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 should 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 1 1 1 1 1 3 3 1 19 14 20 12 15 18 13 14 16 4 4 2 14 15 14 15 14 15 14 15 14 15 14 15 14 15 14 15 0 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
    Hint
    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 illustrates the Manhattan distances from the grayed cell.
     
    Source
    #include<bits/stdc++.h>
    using namespace std;
    #define ll unsigned long long
    #define pi (4*atan(1.0))
    #define eps 1e-14
    #define bug(x)  cout<<"bug"<<x<<endl;
    const int N=2e5+10,M=1e6+10,inf=1e9+10;
    const ll INF=1e18+10,mod=2147493647;
    int n,m;
    double a[110][110], b[1002], x[1002];
    double mp[110][110];
    int Gauss(int N,int M)///M个方程,N个未知数
    {
        int mark = 1;
        for(int i = 1; i <= N && mark <= N; mark++)
        {
            int n = i;
            for(int j = i + 1; j <= M; j++) if(fabs(a[j][mark]) > fabs(a[n][mark])) n = j;
            if(n != i)
            {
                for(int j = mark; j <= N; j++) swap(a[i][j], a[n][j]);
                swap(b[i], b[n]);
            }
            if(fabs(a[i][mark]) < eps) continue;
            for(int j = i + 1; j <= M; j++)
            {
                if(fabs(a[j][mark]) < eps) continue;
    
                double temp = a[j][mark] / a[i][mark];
                for(int k = mark; k <= N; k++)    a[j][k] -= (a[i][k] * temp);
                b[j] -= (b[i] * temp);
            }
            i++;
        }
        int num = 0;
        for(int i = M; i >= 1; i--)
        {
            bool status = false;
            for(int j = N; j >= 1; j--)
            {
                if(fabs(a[i][j]) > eps)
                {
                    status = true;
                    break;
                }
            }
            if(!status && fabs(b[i]) > eps)
                return 0;
            if(status) num++;
            for(int j = N; j > i; j--) b[i] -= a[i][j] * x[j];
            x[i] = b[i] / a[i][i];
        }
        if(num < N)
        {
            return -1;
        }
        return 1;
    }
    int num;
    int getnum(int x,int y)
    {
        return (x-1)*m+y;
    }
    int main()
    {
        int d;
        int fh=0;
        while(~scanf("%d%d%d",&m,&n,&d)&&(n+m+d))
        {
            if(fh++)printf("
    ");
            memset(a,0,sizeof(a));
            for(int i=1;i<=n;i++)
            {
                for(int j=1;j<=m;j++)
                scanf("%lf",&mp[i][j]);
            }
            for(int i=1;i<=n;i++)
            {
                for(int j=1;j<=m;j++)
                {
                    num=0;
                    for(int k=1;k<=n;k++)
                    {
                        for(int l=1;l<=m;l++)
                        {
                            if(abs(k-i)+abs(l-j)<=d)
                            {
                                a[getnum(i,j)][getnum(k,l)]=1;
                                num++;
                            }
                        }
                    }
                    b[getnum(i,j)]=num*mp[i][j];
                }
            }
            Gauss(n*m,n*m);
            for(int i=1;i<=n;i++)
            {
                for(int j=1;j<=m;j++)
                    printf("%8.2f",x[getnum(i,j)]);
                printf("
    ");
            }
        }
        return 0;
    }
  • 相关阅读:
    结对编程-马尔科夫链作业成绩
    结对编程-四则运算(挑战出题)成绩及点评
    结对编程-四则运算成绩
    结对编程-四则运算(挑战出题)
    结对编程
    每天进步一点点-第二天卒
    每天进步一点点-深度学习入门-基于Python的理论与实现 (一)
    今天准备更新每天提高一点点系列
    Books
    WPF命令好状态刷新机制
  • 原文地址:https://www.cnblogs.com/jhz033/p/6269709.html
Copyright © 2011-2022 走看看