在图像opencv python中获取每个通道的对比度

问题描述

如何计算图像中每个通道的对比度? 由于它们there

中有很多对比度定义
  1. 网络对比度
  2. 米歇尔森对比度
  3. RMS对比度

我需要计算这些对比。

解决方法

from PIL import Image
import numpy as np
from numpy import mean,sqrt,square
im = Image.open("leaf.jpg") # Image file name
pixels = list(im.getdata())
width,height = im.size
pixels = np.asarray([pixels[i * width:(i + 1) * width] for i in range(height)],dtype=int)

ch_1 = pixels[:,:,0]
ch_2 = pixels[:,1]
ch_3 = pixels[:,2]

rms_of_ch1 = sqrt(mean(square(ch_1)))
rms_of_ch2 = sqrt(mean(square(ch_2)))
rms_of_ch3 = sqrt(mean(square(ch_3)))