【发布时间】:2018-05-23 21:20:24
【问题描述】:
我正在尝试使用 OpenCV 在 python 中创建 2D 对数色度图。这里也问了同样的问题
How to compute 2D log-chromaticity?
但从未有人回答。
(ASIDE: 有人猜测轴必须是对数而不是线性,但这是不正确的,因为论文使用负坐标,对数轴不能为负数。另外,我很绝望并尝试了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()
输入:
结果:
预期结果:
Finlayson Log Chromaticity Plot
预期结果取自这篇论文(“Intrinsic Images by Entropy Minimization”,作者:Finlayson, G., et. al.):
https://www.cs.sfu.ca/~mark/ftp/Eccv04/
(上面也提到过论文)
你能帮帮我吗?!
【问题讨论】:
-
您可能应该改写标题...这样现在它确实暗示了日志记录,而不是绘制具有对数刻度的图表(或者甚至可能不是这样,正如我进一步阅读的那样)。
-
我一定会改写标题。您对解决这个问题有什么建议吗?
-
不(我在这里肯定超出了我的深度),尽管一些快速挖掘文件试图弄清楚这个情节实际上是什么让我找到了this
-
您介意将此转发给您认识的任何人吗?我很渴望得到答案。非常感谢。
标签: python image opencv colors rgb