Example Analysis of calculating Color richness of Pictures by OpenCV
This article introduces you to OpenCV calculation of image color richness example analysis, the content is very detailed, interested friends can refer to, I hope to help you.
Calculate image color richness
First, we need to have a standard of color richness. Hasler and Süsstrunk's study classified color richness into seven levels.
Not colorful
Slightly colorful
Moderately colorful
Average (Averagely colorful)
Very colorful
Highly colorful
Extremely colorful
Hasler and Süsstrunk asked 20 people to rate 84 images on a scale of 1 to 7. Finally, the survey data analysis, found that the picture color richness has the following calculation formula.
The final C is an indicator of color richness (sigma and miu stand for standard deviation and mean, respectively).
Code import cv2
import numpy as np
def image_colorfulness(image): #Divide the picture into three parts B,G,R (note that R, G, B are vectors instead of scalars) (B, G, R) = cv2.split(image.astype("float")) #rg = R - G rg = np.absolute(R - G) #yb = 0.5 * (R + G) - B yb = np.absolute(0.5 * (R + G) - B) #Calculate the mean and standard deviation of rg and yb (rbMean, rbStd) = (np.mean(rg), np.std(rg)) (ybMean, ybStd) = (np.mean(yb), np.std(yb)) #Calculate the standard deviation and mean of rgyb stdRoot = np.sqrt((rbStd ** 2) + (ybStd ** 2)) meanRoot = np.sqrt((rbMean ** 2) + (ybMean ** 2)) #Return color richness C return stdRoot + (0.3 * meanRoot)
image = cv2.imread ('image path')
print(image_colorfulness(image))
run
#Return image richness value (0-100) About OpenCV calculation image color richness example analysis shared here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.