如何在 Python OpenCV 中绘制图像对数色度图

How to Plot Image Log-Chromaticity Plot in Python OpenCV

我正在尝试使用 OpenCV 在 python 中创建二维对数色度图。在这里问了同样的问题

How to compute 2D log-chromaticity?

但从未得到答复。

(旁白: 猜测轴必须是对数轴而不是线性轴,但这是不正确的,因为论文使用负坐标,并且对数轴不能为负数。另外,我很绝望,尝试了 plt.xscale('log')plt.yscale('log'),但没有用。

这项工作基于这篇论文:

https://www.cs.sfu.ca/~mark/ftp/Eccv04/

(我在下面重新提到)

我的代码:

import numpy as np
import cv2
import os
import matplotlib.pyplot as plt

root = r'.\path\to\root'
root = r'my_img.jpg'

if __name__ == '__main__':

    img = cv2.imread(os.path.join(root, fl))

    cv2.imshow('Original', img)
    cv2.waitKey(0)

    b, g, r = cv2.split(img)

    img_sum = np.sum(img, axis = 2) # NOTE: This dtype will be uint32.
                                    #       Each channel can be up to
                                    #       255 (dtype = uint8), but
                                    #       since uint8 can only go up
                                    #       to 255, sum naturally uint32

    # "Normalized" channels
    # NOTE: np.ma is the masked array library. It automatically masks
    #       inf and nan answers from result

    n_r = np.ma.divide(1.*r, g)
    n_b = np.ma.divide(1.*b, g)

    log_rg = np.ma.log( n_r )
    log_bg = np.ma.log( n_b )

    plt.scatter(l_rg, l_bg, s = 2)
    plt.xlabel('Log(R/G)')
    plt.ylabel('Log(B/G)')
    plt.title('2D Log Chromaticity')
    plt.show()

输入:

Color Checker Chart

结果:

My Log Chromaticity Plot

预期结果:

Finlayson Log Chromaticity Plot

预期结果取自本文("Intrinsic Images by Entropy Minimization",作者:Finlayson, G., et. al.):

https://www.cs.sfu.ca/~mark/ftp/Eccv04/

(论文上面也有提到)

你能帮帮我吗?!

这是我能想到的最接近的。通读:

http://www2.cmp.uea.ac.uk/Research/compvis/Papers/DrewFinHor_ICCV03.pdf

我遇到了这个句子:

"Fig. 2(a) shows log-chromaticities for the 24 surfaces of a Macbeth ColorChecker Chart, (the six neutral patches all belong to the same cluster). If we now vary the lighting and plot median values for each patch, we see the curves in Fig. 2(b)."

如果仔细观察对数色度图,您会看到 19 个斑点,对应于麦克白图表中的 18 种颜色中的每一种,加上底行中所有 6 个灰度目标的总和:

对数色度的解释

对于 1 张图片,我们只能得到每个斑点的 1 个点:我们取每个目标 内的中值 并绘制它。要从论文中获取绘图,我们必须创建多个具有不同光照的图像。我们可以通过在图像编辑器中改变图像的温度来做到这一点。

现在,我只查看了原始图像中的色块并绘制了点:

输入:

输出:

图中的点并不都在纸上的同一个地方,但我认为它相当接近。有人可以检查我的工作,看看这是否有意义吗?