我试图用OpenCV在python中创建一个2D对数色度图。同样的问题也被问到这里
但一直没有人回答。在
(旁白:有人猜测轴必须是对数轴,而不是线性轴,但这是不正确的,因为论文使用负坐标,并且对数轴不能为负。而且,我很绝望,尝试了plt.xscale('log')和{},但没用)。在
这项工作基于本文:
(我在下面再提一下)
我的代码: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()
输入:
结果:
预期结果:
预期结果摘自本文(“通过熵最小化获得的内在图像”,作者:Finlayson,G.,et.al.):
(上述论文也提到)
你能帮帮我吗?!