有没有一种算法可以模糊地返回图像是否存在运动模糊/相机抖动的true/false结果?
理想情况下,它应该特别适用于运动模糊,因为数据集中的许多图像可能具有模糊(Bokeh)背景。
C、Perl、Shell Utility或Python是首选的语言,但我真的很开放。
基于我的目前对数学/编程的了解,我认为我没有希望编写这样的算法,只能使用需要一些参数的算法...
有没有一种算法可以模糊地返回图像是否存在运动模糊/相机抖动的true/false结果?
理想情况下,它应该特别适用于运动模糊,因为数据集中的许多图像可能具有模糊(Bokeh)背景。
C、Perl、Shell Utility或Python是首选的语言,但我真的很开放。
基于我的目前对数学/编程的了解,我认为我没有希望编写这样的算法,只能使用需要一些参数的算法...
要检测模糊度,您可以使用拉普拉斯核将灰度图像卷积,并计算方差。聚焦的图像应具有高方差,而模糊的图像应具有较低的方差。以下是执行此操作的代码:
def is_blur(image) :
"""
This function convolves a grayscale image with
laplacian kernel and calculates its variance.
"""
thresold = #Some value you need to decide
#Laplacian kernel
laplacian_kernel = np.array([[0,1,0],[1,-4,1],[0,1,0]])
laplacian_kernel = tf.expand_dims(laplacian_kernel, -1)
laplacian_kernel = tf.expand_dims(laplacian_kernel, -1)
laplacian_kernel = tf.cast(laplacian_kernel, tf.float32)
#Convolving image with laplacian kernel
new_img = tf.nn.conv2d(image, laplacian_kernel, strides=[1, 1, 1, 1],
padding="SAME")
#Calculating variance
img_var = tf.math.reduce_variance(new_img)
if img_var < thresold :
return True
else :
return False
该函数以灰度图像作为输入,应该是一个4维张量,因为tf.nn.conv2d接受一个4维张量。以下是加载图像的代码:
image_string = tf.io.read_file(ImagePath)
#decoding image
image = tf.image.decode_png(image_string, channels=3)
#Converting image to grayscale
image = tf.image.rgb_to_grayscale(image)
# This will convert to float values in [0, 1]
image = tf.image.convert_image_dtype(image, tf.float32)
#Reshaping image since conv2d accepts a 4-d tensor.
image = tf.reshape(image, shape=[1, image.shape[0], image.shape[1], 1])
你也可以使用Richardson-Lucy算法。它主要用于盲反卷积,但是由于你知道需要去除的是运动模糊,所以RL算法应该需要较少的迭代次数来计算可行的重建。