【问题标题】:How can I calculate the colorspace Delta E in python using only OpenCV/numpy/scipy?如何仅使用 OpenCV/numpy/scipy 在 python 中计算色彩空间 Delta E?
【发布时间】:2020-06-01 02:15:50
【问题描述】:

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

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

怎么做?

【问题讨论】:

    标签: python numpy opencv scipy


    【解决方案1】:

    我认为这很简单。只需从维基百科参考中计算数学。这是一个仅限 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

    【讨论】:

      猜你喜欢
      • 2011-12-30
      • 2019-12-05
      • 2013-04-23
      • 1970-01-01
      • 2013-01-02
      • 2018-09-06
      • 2018-08-19
      • 2020-03-07
      • 1970-01-01
      相关资源
      最近更新 更多