原帖
https://blog.youkuaiyun.com/fightingforcv/article/details/52724848
python版本代码
img = cv2.cvtColor(img, cv2.COLOR_BGR2LAB)
l_channel, a_channel, b_channel = cv2.split(img)
h,w,_ = img.shape
da = a_channel.sum()/(h*w)-128
db = b_channel.sum()/(h*w)-128
histA = [0]*256
histB = [0]*256
for i in range(h):
for j in range(w):
ta = a_channel[i][j]
tb = b_channel[i][j]
histA[ta] += 1
histB[tb] += 1
msqA = 0
msqB = 0
for y in range(256):
msqA += float(abs(y-128-da))*histA[y]/(w*h)
msqB += float(abs(y - 128 - db)) * histB[y] / (w * h)
import math
result = math.sqrt(da*da+db*db)/math.sqrt(msqA*msqA+msqB*msqB)
print("d/m = %s"%result)
本文详细介绍了使用Python和OpenCV进行图像色彩空间转换的方法,具体为从BGR到LAB空间的转换,并对LAB空间中的A、B通道进行统计分析,包括计算平均值和均方差,最后输出色彩差异度。
27万+

被折叠的 条评论
为什么被折叠?



