gpt4 book ai didi

python - 如何仅使用 OpenCV/numpy/scipy 在 python 中计算色彩空间 Delta E?

转载 作者:行者123 更新时间:2023-12-02 17:24:28 25 4
gpt4 key购买 nike

我正在尝试计算 Delta E(参见例如 here )以测量两个不同图像之间的颜色/颜色差异。

我正在遵循 How to compute the Delta E between two images 的方法,但是(部分是为了减少对其他库的依赖),我想仅使用 opencv(和/或 numpy/scipy)及其依赖项在 python 中计算 Delta E。

如何?

最佳答案

我认为这很简单。只需从维基百科引用中计算数学。这是一个 Python/OpenCV/Numpy 唯一的解决方案。

输入 A:

enter image description here

输入 B:

enter image description here

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

关于python - 如何仅使用 OpenCV/numpy/scipy 在 python 中计算色彩空间 Delta E?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60257518/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com