简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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