擅长:python、mysql、java
<p>以上答案是正确的。但是,如果您正在寻找更简化的计算Delta E的方法,即通过避免额外的依赖关系。您可以简单地计算两幅图像之间的欧几里德距离并取平均值</p>
<pre><code>def deltaE(img1, img2, colorspace = cv2.COLOR_BGR2LAB):
# check the two images are of the same size, else resize the two images
(h1, w1) = img1.shape[:2]
(h2, w2) = img1.shape[:2]
h, w = None, None
# check the height
if h1 > h2:
h = h1
else:
h = h2
#check the width
if w1 > w2:
w = w1
else:
w = w2
img1 = cv2.resize(img1, (h,w))
img2 = cv2.resize(img2, (h,w))
# Convert BGR images to specified colorspace
img1 = cv2.cvtColor(img1, colorspace)
img2 = cv2.cvtColor(img2, colorspace)
# compute the Euclidean distance with pixels of two images
return np.sqrt(np.sum((img1 - img2) ** 2, axis=-1))/255.
</code></pre>