理论
Vollath函数定义如下:
其中:
为整幅图像的平均灰度值,M和N分别为图像宽和高。
https://blog.csdn.net/Real_Myth/article/details/50827940
代码
def Vollath(img):''':param img:narray 二维灰度图像:return: float 图像约清晰越大'''shape = np.shape(img)u = np.mean(img)out = -shape[0]*shape[1]*(u**2)for x in range(0, shape[0]-1):for y in range(0, shape[1]):out+=int(img[x,y])*int(img[x+1,y])return out
https://blog.csdn.net/Greepex/article/details/90183018
def _Vollath(self,imgName):"""灰度方差乘积:param imgName::return:"""# step 1 图像的预处理img2gray, reImg = self.preImgOps(imgName)f = self._imageToMatrix(img2gray)source=0x,y=f.shapefor i in range(x-1):for j in range(y):source+=f[i,j]*f[i+1,j]source=source-x*y*np.mean(f)# strp3: 绘制图片并保存 不应该写在这里 抽象出来 这是共有的部分newImg = self._drawImgFonts(reImg, str(source))newDir = self.strDir + "/_Vollath_/"if not os.path.exists(newDir):os.makedirs(newDir)newPath = newDir + imgNamecv2.imwrite(newPath, newImg) # 保存图片cv2.imshow(imgName, newImg)cv2.waitKey(0)return source
https://github.com/Leezhen2014/python—/blob/master/BlurDetection.py
8. Vollath函数
Vollath函数定义如下:
其中: u为整幅图像的平均灰度值,M和N分别为图像宽和高。
代码:
def Vollath(img):# 图像的预处理reImg = cv2.resize(img, (800, 900), interpolation=cv2.INTER_CUBIC)img2gray = cv2.cvtColor(reImg, cv2.COLOR_BGR2GRAY) #f = self._imageToMatrix(img2gray)D = 0x,y=f.shapefor i in range(x-1):for j in range(y):D += f[i,j]*f[i+1,j]D = D - x * y * np.mean(f)return D
https://gist.github.com/JuneoXIE/d595028586eec752f4352444fc062c44
