简体   繁体   English

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

[英]Get contrast for each channel in an image opencv python

How to calculate each channel contrast in images?如何计算图像中每个通道的对比度? Since they are lot of contrast definitions out there因为它们很多对比定义

  1. Webar Contrast网吧对比
  2. Michelson Contrast迈克尔逊对比
  3. RMS contrast RMS 对比度

I need to calculate these contrasts.我需要计算这些对比。

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)))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM