最近在畢業(yè)設(shè)計(jì)中涉及了有關(guān)增強(qiáng)圖像清晰度的實(shí)驗(yàn),需要一些指標(biāo)來(lái)進(jìn)行實(shí)驗(yàn)結(jié)果的評(píng)估。剛好網(wǎng)上有個(gè)總結(jié)的非常好的博客(見(jiàn)參考文獻(xiàn)[1]),但沒(méi)有實(shí)現(xiàn)方法。因此,我將在我的博客中用Python實(shí)現(xiàn)。
評(píng)估方法實(shí)現(xiàn)
所有函數(shù)的具體說(shuō)明都在參考文獻(xiàn)[1]里,這里不做過(guò)多的贅述,
只討論實(shí)現(xiàn)
。
github:圖像清晰度評(píng)估算法包(有示例)
1 Brenner 梯度函數(shù)
def brenner(img):
'''
:param img:narray 二維灰度圖像
:return: float 圖像約清晰越大
'''
shape = np.shape(img)
out = 0
for x in range(0, shape[0]-2):
for y in range(0, shape[1]):
out+=(int(img[x+2,y])-int(img[x,y]))**2
return out
2 Laplacian梯度函數(shù)
def Laplacian(img):
'''
:param img:narray 二維灰度圖像
:return: float 圖像約清晰越大
'''
return cv2.Laplacian(img,cv2.CV_64F).var()
3 SMD(灰度方差)
def SMD(img):
'''
:param img:narray 二維灰度圖像
:return: float 圖像約清晰越大
'''
shape = np.shape(img)
out = 0
for x in range(0, shape[0]-1):
for y in range(1, shape[1]):
out+=math.fabs(int(img[x,y])-int(img[x,y-1]))
out+=math.fabs(int(img[x,y]-int(img[x+1,y])))
return out
4 SMD2(灰度方差乘積)
def SMD2(img):
'''
:param img:narray 二維灰度圖像
:return: float 圖像約清晰越大
'''
shape = np.shape(img)
out = 0
for x in range(0, shape[0]-1):
for y in range(0, shape[1]-1):
out+=math.fabs(int(img[x,y])-int(img[x+1,y]))*math.fabs(int(img[x,y]-int(img[x,y+1])))
return out
5 方差函數(shù)
def variance(img):
'''
:param img:narray 二維灰度圖像
:return: float 圖像約清晰越大
'''
out = 0
u = np.mean(img)
shape = np.shape(img)
for x in range(0,shape[0]):
for y in range(0,shape[1]):
out+=(img[x,y]-u)**2
return out
6 能量梯度函數(shù)
def energy(img):
'''
:param img:narray 二維灰度圖像
:return: float 圖像約清晰越大
'''
shape = np.shape(img)
out = 0
for x in range(0, shape[0]-1):
for y in range(0, shape[1]-1):
out+=((int(img[x+1,y])-int(img[x,y]))**2)+((int(img[x,y+1]-int(img[x,y])))**2)
return out
7 Vollath函數(shù)
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
8 熵函數(shù)
def entropy(img):
'''
:param img:narray 二維灰度圖像
:return: float 圖像約清晰越大
'''
out = 0
count = np.shape(img)[0]*np.shape(img)[1]
p = np.bincount(np.array(img).flatten())
for i in range(0, len(p)):
if p[i]!=0:
out-=p[i]*math.log(p[i]/count)/count
return out
參考文獻(xiàn)
[1] 圖像清晰度的評(píng)價(jià)指標(biāo)
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
