简体   繁体   English

在matlab中提取图像的运动模糊

[英]extract motion blur of an image in matlab

I found that there are some paper said can analysis the gradient histogram (blur image has gradient follows a heavy-tailed distribution) or using fft (blur image has lower frequency) Is there a way to detect if an image is blurry? 我发现有一些纸说可以分析梯度直方图(模糊图像有梯度跟随重尾分布)或使用fft(模糊图像有较低的频率) 有没有办法检测图像是否模糊? to detect blur in image. 检测图像中的模糊。

But I am not quite sure how to implement it in matlab. 但我不太确定如何在matlab中实现它。 How to define the threshold value and so on. 如何定义阈值等。

[Gx, Gy] = imgradientxy(a);
G = sqrt(Gx.^2+Gy.^2)

What should I do after running the command and find the G ? 运行命令后我该怎么办才能找到G What should I do if I wanna plot a graph of number of pixel verse G 如果我想绘制number of pixel G的图表,我该怎么办?

I am new to matlab and image processing. 我是matlab和图像处理的新手。 Could anyone kindly provide more details of how to implement it 任何人都可以提供有关如何实施它的更多细节

Preparation: we read the cameraman image, which is often used for visualizing image processing algorithms, and add some motion blur. 准备:我们读取摄影师图像,该图像通常用于可视化图像处理算法,并添加一些运动模糊。

origIm = imread('cameraman.tif');
littleBlurredIm = imfilter(origIm,fspecial('motion',5,45),'replicate');
muchBlurredIm = imfilter(origIm,fspecial('motion',20,45),'replicate');

which gives us the following images to start with: 这给我们以下图像开头:

开始图像

To calculate the Laplacian, you can use the imgradient function, which returns magnitude and angle, so we'll simply discard the angle: 要计算拉普拉斯算子,你可以使用imgradient函数,它返回幅度和角度,所以我们只需丢弃角度:

[lpOrigIm,~] =  imgradient(origIm);
[lpLittleBlurredIm,~] = imgradient(littleBlurredIm);
[lpMuchBlurredIm,~] = imgradient(muchBlurredIm);

which gives: 这使:

过滤后的图像

You can visually see that the original image has very sharp and clear edges. 您可以直观地看到原始图像边缘清晰锐利。 The image with a little blur still has some features, and the image with much blur only contains a few non-zero values. 具有少量模糊的图像仍然具有一些特征,并且具有大量模糊的图像仅包含一些非零值。

As proposed in the answer by nikie to this question , we can now create some measure for the blurriness. 正如nikie对这个问题的回答所提出的 ,我们现在可以为模糊性创建一些衡量标准。 A (more or less) robust measure would for example be the median of the top 0.1% of the values: 例如,(或多或少)稳健度量将是值的前0.1%的中值:

% Number of pixels to look at: 0.1%
nPx = round(0.001*numel(origIm));

% Sort values to pick top values
sortedOrigIm = sort(lpOrigIm(:));
sortedLittleBlurredIm = sort(lpLittleBlurredIm(:));
sortedMuchBlurredIm = sort(lpMuchBlurredIm(:));

% Calculate measure
measureOrigIm = median(sortedOrigIm(end-nPx+1:end));
measureLittleBlurredIm = median(sortedLittleBlurredIm(end-nPx+1:end));
measureMuchBlurredIm = median(sortedMuchBlurredIm(end-nPx+1:end));

Which gives the following results: 这给出了以下结果:

 Original image: 823.7 Little Blurred image: 593.1 Much Blurred image: 490.3 

Here is a comparison of this blurriness measure for different motion blur angles and blur amplitudes. 以下是针对不同运动模糊角度和模糊幅度的这种模糊度量的比较。

模糊

Finally, I tried it on the test images from the answer linked above: 最后,我在上面链接的答案的测试图像上尝试了它:

测试图像

which gives 这使

模糊测试图像

Interpretation: As you see it is possible to detect, if an image is blurred. 解释:如您所见,如果图像模糊,则可以检测到。 It however appears difficult to detect how strongly blurred the image is, as this also depends on the angle of the blur with relation to the scene, and due to the imperfect gradient calculation. 然而,似乎难以检测图像的强烈模糊,因为这还取决于模糊相对于场景的角度,并且由于不完美的梯度计算。 Further the absolute value is very much scene-dependent, so you might have to put some prior knowledge about the scene into the interpretation of this value. 此外,绝对值与场景有很大关系,因此您可能必须将有关场景的一些先验知识放入此值的解释中。

This is a very interesting topic. 这是一个非常有趣的话题。 Although gradient magnitude can be used as good feature for blur detection but this feature will fail when dealing with uniform regions in images. 虽然梯度幅度可以用作模糊检测的良好特征,但是当处理图像中的均匀区域时,该特征将失败。 In other words, this feature will not be able to distinguish between blur and flat regions. 换句话说,此功能将无法区分模糊和平坦区域。 There are many other solutions. 还有许多其他解决方案。 Some of them detect flat regions to avoid classifying flat regions as blur. 其中一些检测平坦区域以避免将平坦区域分类为模糊。 if you want more information you can check these links: 如果您想了解更多信息,可以查看以下链接:

You can find many good recent papers in cvpr conference. 你可以在cvpr会议上找到很多好的近期论文。 Many of them they have websites where they discuss the details and provide the code. 他们中的许多人都有网站,他们讨论细节并提供代码。 This one http://www.cse.cuhk.edu.hk/leojia/projects/dblurdetect/ is one of the papers that I worked on you can find the code available. 这个http://www.cse.cuhk.edu.hk/leojia/projects/dblurdetect/是我工作过的论文之一,你可以找到可用的代码。 You can check also other papers in cvpr. 您还可以查看cvpr中的其他论文。 most of them they have the code this is another one http://shijianping.me/jnb/index.html 他们中的大多数都有代码,这是另一个http://shijianping.me/jnb/index.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM