我试图获得图像的模糊度。我参考本教程计算开cv中laplacian的方差。
import cv2
def variance_of_laplacian(image):
return cv2.Laplacian(image, cv2.CV_64F).var()
def check_blurry(image):
"""
:param: the image
:return: True or False for blurry
"""
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
fm = variance_of_laplacian(gray)
return fm当我试图从两幅图像中计算fm时,这两幅图像看起来完全相同,但大小不同。
filePath = 'small.jpeg'
image1 = cv2.imread(filePath)
print('small image shape', image1.shape)
print('small image fm', check_blurry(image1))
filePath = 'large.jpg'
image2 = cv2.imread(filePath)
print('large image shape', image2.shape)
print('large image fm', check_blurry(image2))信息系统的产出:
small image shape (1440, 1080, 3)
small image fm 4.7882723403428065
large image shape (4032, 3024, 3)
large image fm 8.44476634687877很明显,小图像缩小了大图像的2.8比。fm与图像大小有关吗?如果是的话,他们之间有什么关系?或者有什么方法来评估不同大小图像的模糊程度?
发布于 2018-04-14 16:35:22
“fm与图像大小相关吗?”
是的,部分地(至少就你的问题而言),因为如果你缩放一幅图像,你必须插值像素值。向下缩放不仅会丢失信息,还会通过像素插值(如果不是最近邻插值)创建新信息,从而影响图像的方差。但这只适用于缩放图像,而不适用于最初不同的图像。
https://stackoverflow.com/questions/49808127
复制相似问题