理论
Brenner梯度函数是最简单的梯度评价函数,它只是简单的计算相邻两个像素灰度差的平方,该函数定义如下:
其中: 表示图像f对应像素点的灰度值,为图像清晰度计算结果。
https://blog.csdn.net/Real_Myth/article/details/50827940
算法
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
https://blog.csdn.net/Greepex/article/details/90183018
###########################################
def ImageToMatrix(dir,name):
# 读取图片
im = Image.open(dir+name)
# 显示图片
#im.show()
width,height = im.size
im = im.convert("L")
data = im.getdata()
data = np.matrix(data,dtype='float')/255.0
new_data = np.reshape(data,(height,width))
return new_data
def Brenner(img):
x, y = img.shape
D = 0
for i in range(x-2):
for j in range(y-2):
D += (img[i+2, j] - img[i, j])**2
return D
def TestBrener():
dir = "D:/document/ZKBH/bug/face/"
imgList = getAllImg(dir)
for i in range(len(imgList)):
frame = ImageToMatrix(dir , imgList[i])
score = Brenner(frame)
print(str(imgList[i]) + " is " + str(score))
###########################################
def ImageToMatrix(dir,name):
# 读取图片
im = Image.open(dir+name)
# 显示图片
#im.show()
width,height = im.size
im = im.convert("L")
data = im.getdata()
data = np.matrix(data,dtype='float')/255.0
new_data = np.reshape(data,(height,width))
return new_data
def Brenner(img):
x, y = img.shape
D = 0
for i in range(x-2):
for j in range(y-2):
D += (img[i+2, j] - img[i, j])**2
return D
def TestBrener():
dir = "D:/document/ZKBH/bug/face/"
imgList = getAllImg(dir)
for i in range(len(imgList)):
frame = ImageToMatrix(dir , imgList[i])
score = Brenner(frame)
print(str(imgList[i]) + " is " + str(score))
################################
https://www.cnblogs.com/greentomlee/p/9379471.html
## 2. Brenner 梯度函数
Brenner梯度函数是最简单的梯度评价函数,它只是简单的计算相邻两个像素灰度差的平方,该函数定义如下:
![](https://ws1.sinaimg.cn/large/cdd040eely1g46bosf58xj20890123yn.jpg)
其中:f(x,y) 表示图像f对应像素点(x,y)的灰度值,D(f)为图像清晰度计算结果(下同)。
**代码:**
```
def Brenner(img): x, y = img.shape D = 0 for i in range(x-2): for j in range(y-2): D += (img[i+2, j] - img[i, j])**2 return D ``` https://gist.github.com/JuneoXIE/d595028586eec752f4352444fc062c44