使用opencv通过去卷积去模糊图像 [英] deblurring image by deconvolution using opencv
问题描述
我有两张图片 o1
& o2
,我使用相同的高斯模糊内核模糊了两个图像。然后我发现内核 k1 = DFT(b1)/ DFT(o1)
,其中 b1
是获得的图像模糊 o1
。
I have two images o1
& o2
, and I have blurred the two images using the same Gaussian blurring kernel. Then I have found kernel k1 = DFT(b1) / DFT (o1)
, where b1
is the image obtained by blurring o1
.
我用过这个核心( k1
)在 b2
上执行反卷积,其中 b2
是通过模糊 o2 $获得的c $ c>。
I have used this kernal (k1
) to perform deconvolution on b2
, where b2
is obtained by blurring o2
.
但是deblurred输出不正确(输出图像与原始图像没有任何关系)我的代码中有什么问题?
But deblurred output is not correct (the output image does not have any relation with original) what is the problem in my code ?
int main(int argc, char** argv)
{
Mat orig1 = imread(argv[1], 0);
Mat orig2 = imread(argv[2], 0);
Mat blur1, blur2;
GaussianBlur(orig1, blur1, Size(11, 11), 0, 0 );
GaussianBlur(orig2, blur2, Size(11, 11), 0, 0 );
imshow("or1", orig1);
imshow("bl1", blur1);
imshow("or2", orig2);
imshow("bl2", blur2);
waitKey(0);
deconvolution(orig1, blur1, orig2, blur2);
return 0;
}
void deconvolution(Mat & o1, Mat & b1, Mat & o2, Mat & b2)
{
Mat o1f, o2f, b1f, b2f;
Mat o1dft, o2dft, b1dft, b2dft;
o1.convertTo(o1f, CV_32F);
b1.convertTo(b1f, CV_32F);
o2.convertTo(o2f, CV_32F);
b2.convertTo(b2f, CV_32F);
computeDFT(o1f, o1dft);
computeDFT(b1f, b1dft);
computeDFT(o2f, o2dft);
computeDFT(b2f, b2dft);
Mat k1, k2, b1d, b2d;
divide(b1dft, o1dft, k1);
Mat r1, r2;
divide(b1dft, k1, r1);
divide(b2dft, k1, r2);
Mat idftr1, idftr2;
computeIDFT(r1, idftr1);
computeIDFT(r2, idftr2);
Mat r1_8u, r2_8u;
idftr1.convertTo(r1_8u, CV_8U);
idftr2.convertTo(r2_8u, CV_8U);
imshow("r1", r1_8u);
imshow("r2", r2_8u);
waitKey(0);
destroyAllWindows();
}
图片o1,o2,b1,b2, r1
和 r2
按顺序给出:
Images o1, o2, b1, b2, r1
and r2
are given in order below:
推荐答案
问题很可能是你的模糊内核对某些频率有消失的系数。对于信号(f)和模糊内核(h)的每个变换系数,您现在可以计算f / h。对于这些系数,这实际上是零除,导致您观察到的强噪声。
The problem is most likely that your blurring kernel has vanishing coefficients for certain frequencies. For each coefficient of the transform of your signal (f) and blurring kernel (h), you calculate f/h right now. This is effectively a division by zero for these coefficients, resulting in the strong noise you observe.
对此的快速解决方案是伪逆滤波:
A quick solution for this would be pseudo-inverse filtering:
仅对| h |使用f / h > epsilon
use f/h only for |h| > epsilon
将系数设置为0其他
如果这不够顺利,您可以获得更好的结果使用
维纳过滤。
If this isn't smooth enough, you can get better results with wiener filtering.
这篇关于使用opencv通过去卷积去模糊图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!