我想知道是否有一种方法可以通过分析图像数据来确定图像是否模糊。
当前回答
上面的回答阐明了许多事情,但我认为做一个概念上的区分是有用的。
如果你对一个模糊的图像拍摄一张完美对焦的照片呢?
The blurring detection problem is only well posed when you have a reference. If you need to design, e.g., an auto-focus system, you compare a sequence of images taken with different degrees of blurring, or smoothing, and you try to find the point of minimum blurring within this set. I other words you need to cross reference the various images using one of the techniques illustrated above (basically--with various possible levels of refinement in the approach--looking for the one image with the highest high-frequency content).
其他回答
我想到了一个完全不同的解决方案。 我需要分析视频静止帧,以便在每(X)帧中找到最清晰的帧。这样,我将检测运动模糊和/或失焦图像。
我最终使用了Canny边缘检测,我得到了非常非常好的结果,几乎每一种视频(与尼基的方法,我有数字化的VHS视频和沉重的交错视频的问题)。
我通过在原始图像上设置感兴趣区域(ROI)来优化性能。
使用EmguCV:
//Convert image using Canny
using (Image<Gray, byte> imgCanny = imgOrig.Canny(225, 175))
{
//Count the number of pixel representing an edge
int nCountCanny = imgCanny.CountNonzero()[0];
//Compute a sharpness grade:
//< 1.5 = blurred, in movement
//de 1.5 à 6 = acceptable
//> 6 =stable, sharp
double dSharpness = (nCountCanny * 1000.0 / (imgCanny.Cols * imgCanny.Rows));
}
在这篇文章中,我尝试了基于拉普拉斯滤波器的解决方案。这对我没有帮助。所以,我尝试了这篇文章中的解决方案,它对我的情况很好(但很慢):
import cv2
image = cv2.imread("test.jpeg")
height, width = image.shape[:2]
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
def px(x, y):
return int(gray[y, x])
sum = 0
for x in range(width-1):
for y in range(height):
sum += abs(px(x, y) - px(x+1, y))
较少模糊的图像具有最大和值!
你也可以通过改变步长来调整速度和准确度。
这部分
for x in range(width - 1):
你可以用这个替换
for x in range(0, width - 1, 10):
我在matlab中使用FFT实现了它,并检查FFT的直方图,计算平均值和STD,还可以做拟合函数
fa = abs(fftshift(fft(sharp_img)));
fb = abs(fftshift(fft(blured_img)));
f1=20*log10(0.001+fa);
f2=20*log10(0.001+fb);
figure,imagesc(f1);title('org')
figure,imagesc(f2);title('blur')
figure,hist(f1(:),100);title('org')
figure,hist(f2(:),100);title('blur')
mf1=mean(f1(:));
mf2=mean(f2(:));
mfd1=median(f1(:));
mfd2=median(f2(:));
sf1=std(f1(:));
sf2=std(f2(:));
在高度重视的期刊(IEEE Transactions on Image Processing)上发表的两种方法的Matlab代码可在这里获得:https://ivulab.asu.edu/software
检查CPBDM和JNBM算法。如果你检查代码,它并不难移植,顺便说一下,它是基于Marzialiano的方法作为基本特征。
估计图像清晰度的另一种非常简单的方法是使用拉普拉斯(或LoG)滤波器,并简单地选择最大值。如果你期待噪音,使用像99.9%分位数这样的稳健测量可能会更好(即选择第n高的对比度而不是最高的对比度)。如果你希望图像亮度变化,你还应该包括一个预处理步骤来标准化图像亮度/对比度(例如直方图均衡化)。
我已经在Mathematica中实现了Simon的建议,并在一些测试图像上进行了尝试:
第一个测试使用不同内核大小的高斯滤波器模糊测试图像,然后计算模糊图像的FFT,并取90%最高频率的平均值:
testFft[img_] := Table[
(
blurred = GaussianFilter[img, r];
fft = Fourier[ImageData[blurred]];
{w, h} = Dimensions[fft];
windowSize = Round[w/2.1];
Mean[Flatten[(Abs[
fft[[w/2 - windowSize ;; w/2 + windowSize,
h/2 - windowSize ;; h/2 + windowSize]]])]]
), {r, 0, 10, 0.5}]
得到对数图:
5条线代表5张测试图像,X轴代表高斯滤波半径。图像是递减的,因此FFT是一个很好的度量清晰度的方法。
这是“最高LoG”模糊估计器的代码:它简单地应用一个LoG过滤器,并返回过滤结果中最亮的像素:
testLaplacian[img_] := Table[
(
blurred = GaussianFilter[img, r];
Max[Flatten[ImageData[LaplacianGaussianFilter[blurred, 1]]]];
), {r, 0, 10, 0.5}]
得到对数图:
这里未模糊图像的传播稍微好一点(2.5 vs 3.3),主要是因为这种方法只使用图像中最强的对比度,而FFT本质上是整个图像的平均值。函数的减少速度也更快,所以设置一个“模糊”阈值可能更容易。
推荐文章
- 使用ImageMagick“Diff”图像
- 如何使用pip安装opencv ?
- 如何用OpenCV2.0和Python2.6调整图像大小
- 如何消除数独方块的凹凸缺陷?
- ImportError: numpy.core.multiarray导入失败
- 我如何量化两幅图像之间的差异?
- 有没有办法检测图像是否模糊?
- 简单和快速的方法来比较图像的相似性
- 如何合并一个透明的png图像与另一个图像使用PIL
- 提取和保存视频帧
- 如何使用c#裁剪图像?
- 什么是最好的java图像处理库/方法?
- 给出一个图像来表示和解决一个迷宫
- 如何通过Conda安装Python OpenCV ?
- 推荐使用ImageMagick压缩JPG文件