from PIL import Image, ImageStat
import numpy as np
import matplotlib.pyplot as plt
from cv2 import cv2
import numpy as np
def contrast(img0):
img1 = cv2.cvtColor(img0, cv2.COLOR_BGR2GRAY) # 彩色转为灰度图片
m, n = img1.shape
# 图片矩阵向外扩展一个像素
img1_ext = cv2.copyMakeBorder(img1, 1, 1, 1, 1, cv2.BORDER_REPLICATE)
rows_ext, cols_ext = img1_ext.shape
b = 0.0
for i in range(1, rows_ext - 1):
for j in range(1, cols_ext - 1):
b += ((img1_ext[i, j] - img1_ext[i, j + 1]) ** 2 + (img1_ext[i, j] - img1_ext[i, j - 1]) ** 2 +
(img1_ext[i, j] - img1_ext[i + 1, j]) ** 2 + (img1_ext[i, j] - img1_ext[i - 1, j]) ** 2)
cg = b / (4 * (m - 2) * (n - 2) + 3 *
图像亮度、对比度计算
最新推荐文章于 2024-07-25 04:22:40 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)