用高斯消元对高斯模糊的图像还原....

Kind of a Blur

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

Total Submission(s): 1321    Accepted Submission(s): 383

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 <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath> using namespace std; const double eps=1e-8;
const int maxn=130; double data[maxn/10][maxn/10],a[maxn][maxn],x[maxn];
int n,m,d; int equ,val; void Gauss()
{
int k,col,mar;
for(k=0,col=0;k<equ&&col<val;k++,col++)
{
mar=k;
for(int i=k+1;i<equ;i++)
{
if(fabs(a[i][col])>fabs(a[mar][col]))
mar=i;
}
if(fabs(a[mar][col])<eps) return ;
if(k!=mar)
{
for(int i=col;i<val;i++)
swap(a[k][i],a[mar][i]);
swap(x[k],x[mar]);
}
x[k]/=a[k][col];
for(int i=col+1;i<val;i++)
a[k][i]/=a[k][col];
a[k][col]=1.;
for(int i=0;i<equ;i++)
{
if(i==k) continue;
x[i]-=x[k]*a[i][col];
for(int j=col+1;j<val;j++)
a[i][j]-=a[k][j]*a[i][col];
a[i][col]=0;
}
}
} int main()
{
bool fst=false;
while(scanf("%d%d%d",&m,&n,&d)!=EOF)
{
if(n==0&&m==0) break;
if(fst) putchar(10);
else fst=true;
memset(a,0,sizeof(a));
memset(x,0,sizeof(x));
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
scanf("%lf",&data[i][j]);
int cnt=0;
int t1=i*m+j,t2=0;
for(int ii=0;ii<n;ii++)
{
for(int jj=0;jj<m;jj++)
{
if(abs(i-ii)+abs(j-jj)<=d)
{
t2=ii*m+jj;
a[t2][t1]=1.;
cnt++;
}
}
}
x[t1]=data[i][j]*cnt;
}
}
equ=val=n*m;
Gauss();
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
printf("%8.2lf",x[i*m+j]);
}
putchar(10);
}
}
return 0;
}

HDOJ 3359 Kind of a Blur的更多相关文章

  1. hdu 3359 Kind of a Blur (高斯消元 浮点型)

    题目链接 题意: H * W (W,H <= 10) 的矩阵A的某个元素A[i][j],从它出发到其他点的曼哈顿距离小于等于D的所有值的和S[i][j]除上可达点的数目,构成了矩阵B.给定矩阵B ...

  2. HDU 3359 Kind of a Blur(高斯消元)

    题意: H * W (W,H <= 10) 的矩阵A的某个元素A[i][j],从它出发到其他点的曼哈顿距离小于等于D的所有值的和S[i][j]除上可达点的数目,构成了矩阵B.给定矩阵B,求矩阵A ...

  3. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  4. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  5. HDOJ 1326. Box of Bricks 纯水题

    Box of Bricks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  6. 解决css3毛玻璃效果(blur)有白边问题

    做一个登录页,全屏背景图毛玻璃效果,实现方法如下: HTML: <body> <div class="login-wrap"> <div class= ...

  7. js(jquery)解决input元素的blur事件和其他非表单元素的click事件冲突的方法

    HTML结构:很简单,就一个input,一个div,能说明问题就OK了: <input type="text" value="默认值"><br ...

  8. blur和click事件的先后顺序问题

    这两个同时用会有冲突.懒得翻译了,需要的自己看哈. 以下摘自stackoverflow. I have an input field, where I try to make autocomplete ...

  9. HDOJ 1004 Let the Balloon Rise

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

随机推荐

  1. [NC189C]硬币游戏

    题目大意:有$4n$个硬币,放在$2n$个位置(即放成两排),有两个人,轮流取.第一个人取上面的,第二个人取下面的,每个人只可以取两个人都没取过的位置.若硬币正面向上,为$1$,反面为$0$.把取得的 ...

  2. 洛谷 P2173 [ZJOI2012]网络 解题报告

    P2173 [ZJOI2012]网络 题目描述 有一个无向图G,每个点有个权值,每条边有一个颜色.这个无向图满足以下两个条件: 对于任意节点连出去的边中,相同颜色的边不超过两条. 图中不存在同色的环, ...

  3. Codeforces Round #357 (Div. 2) A

    A. A Good Contest time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  4. hihocoder 1457 后缀自动机四·重复旋律7 求不同子串的和

    描述 小Hi平时的一大兴趣爱好就是演奏钢琴.我们知道一段音乐旋律可以被表示为一段数构成的数列. 神奇的是小Hi发现了一部名字叫<十进制进行曲大全>的作品集,顾名思义,这部作品集里有许多作品 ...

  5. 「BZOJ4029」[HEOI2015] 定价 贪心

    「BZOJ4029」[HEOI2015] 定价 2015年4月28日2,7490 Description 在市场上有很多商品的定价类似于 999 元.4999 元.8999 元这样.它们和 1000 ...

  6. js获取url参数,操作url参数

    function getParam(key) { var tmp = location.search; tmp = decodeURIComponent(tmp); var index = tmp.i ...

  7. hdu 4679 树的直径

    /* 题目大意:给n个点n-1条边的树,求删除哪条边时两个树中最大的直径与边权的乘积最小. 树的直径(Diameter)是指树上的最长简单路. 直径的求法:两遍BFS (or DFS) 若删除的边不是 ...

  8. centos7配置环境LNMP

    #yum安装epel-release第三方软件包 yum install epel-release #要验证EPEL仓库是否建立成功 yum repolist xshell访问系统出现中文乱码的解决方 ...

  9. Custom Email Attribute在客户端不起作用原因

    原文发布时间为:2011-07-16 -- 来源于本人的百度文章 [由搬家工具导入] Custom Email Attribute在客户端不起作用原因,就是未实现 IClientValidatable ...

  10. 华为上机测试题(求亮灯数量-java)

    PS:自己写的,自测试OK,供大家参考. /* 一条长廊里依次装有n(1 ≤ n ≤ 65535)盏电灯,从头到尾编号1.2.3.…n-1.n.每盏电灯由一个拉线开关控制.开始,电灯全部关着.有n个学 ...