在2D散点图中以真实色彩(RGB)显示cielab(a * b)

时间:2019-10-22 08:39:01

标签: python matplotlib

我有一个RGB图像,我将其转换为实验室空间(L a b)。接下来,我为“ a”和“ b”创建了一个二维散点图。现在,我想用相应的实验室空间颜色可视化数据点。 下面是所需的图:

Desired 2D scatter plot

到目前为止,我已经尝试过:

# Load libraries
import matplotlib.pyplot as plt
from matplotlib import 
from matplotlib import cm
from matplotlib import colors
import cv2
import numpy as np


# Random RGB
rgb = np.random.randint(255, size=(900,800,3),dtype=np.uint8)
cv2.imshow('RGB',rgb)

# Convert to LAB space
lab = cv2.cvtColor(rgb, cv2.COLOR_RGB2LAB)

# Split channels
l, a, b = cv2.split(lab)

# Convert 2D to 1D vector
a1d = a.flat
b1d = b.flat
# Plot 2D scatter plot for 'a' and 'b'
plt.scatter(a, b)
plt.xlabel('a')
plt.ylabel('b')
plt.colorbar()
plt.show()

非常感谢你们。

0 个答案:

没有答案