【发布时间】:2020-06-01 02:15:50
【问题描述】:
我正在尝试计算 Delta E(参见例如here),以测量两个不同图像之间的颜色/颜色差异。
我正在遵循How to compute the Delta E between two images 的方法,但是(部分是为了减少对其他库的依赖),我想仅使用 opencv(和/或 numpy)在 python 中计算 Delta E /scipy) 及其依赖项。
怎么做?
【问题讨论】:
我正在尝试计算 Delta E(参见例如here),以测量两个不同图像之间的颜色/颜色差异。
我正在遵循How to compute the Delta E between two images 的方法,但是(部分是为了减少对其他库的依赖),我想仅使用 opencv(和/或 numpy)在 python 中计算 Delta E /scipy) 及其依赖项。
怎么做?
【问题讨论】:
我认为这很简单。只需从维基百科参考中计算数学。这是一个仅限 Python/OpenCV/Numpy 的解决方案。
输入 A:
输入 B:
import cv2
import numpy as np
# read image_A and convert to float
image_A = cv2.imread('barn.jpg').astype("float32")
# read image_B as grayscale and convert to float
image_B = cv2.imread('barn_mod.jpg').astype("float32")
# convert image_A and image_B from BGR to LAB
image_A = cv2.cvtColor(image_A,cv2.COLOR_BGR2LAB)
image_B = cv2.cvtColor(image_B,cv2.COLOR_BGR2LAB)
# compute difference
diff = cv2.add(image_A,-image_B)
# separate into L,A,B channel diffs
diff_L = diff[:,:,0]
diff_A = diff[:,:,1]
diff_B = diff[:,:,2]
# compute delta_e as mean over every pixel using equation from
# https://en.wikipedia.org/wiki/Color_difference#CIELAB_ΔE*
delta_e = np.mean( np.sqrt(diff_L*diff_L + diff_A*diff_A + diff_B*diff_B) )
# print results
print (delta_e)
delta_e:
0.29771116
另见:
https://python-colormath.readthedocs.io/en/latest/delta_e.html
https://python-colormath.readthedocs.io/en/latest/_modules/colormath/color_diff.html
https://github.com/scikit-image/scikit-image/blob/master/skimage/color/delta_e.py
【讨论】: