假设我有一个opencv BGR图像img,如何计算该图像的对比度?
发布于 2019-11-12 22:52:19
对比度的一个定义是RMS Contrast,它可以计算如下:
首先,将BGR图像img转换为灰度:
img_grey = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)最后,计算灰度图像像素强度的标准差:
contrast = img_grey.std()发布于 2019-11-13 04:17:42
这里有一个对比度的度量:Michelson contrast以及如何在Python/OpenCV/Numpy中计算它。低对比度接近零,高对比度接近一。使用YUV或YCbCr中的Y(强度)通道或实验室中的L通道,甚至只是将图像转换为灰度并使用它。
输入:

import cv2
import numpy as np
# load image as YUV (or YCbCR) and select Y (intensity)
# or convert to grayscale, which should be the same.
# Alternately, use L (luminance) from LAB.
img = cv2.imread("barn.jpg")
Y = cv2.cvtColor(img, cv2.COLOR_BGR2YUV)[:,:,0]
# compute min and max of Y
min = np.min(Y)
max = np.max(Y)
# compute contrast
contrast = (max-min)/(max+min)
print(min,max,contrast)
返回:
0 255 1.0
对比度将介于0和1之间。
https://stackoverflow.com/questions/58821130
复制相似问题