为RGB数据制作颜色条?

问题描述 投票:0回答:1

我获得了基于3个通道的数据,这些通道是红色的RGB,这意味着颜色条必须在所有3种颜色之间循环以显示所有可能的阴影是否有一种简单的方法可以做到这一点?

这是一个例子。红色增强,蓝色增强,绿色增强。 (它正在观察光谱特征。)这意味着红色+蓝色(=紫色)将是正确的,中央增强,左侧弱。等等

我需要一种方法来正确显示各种颜色条。

enter image description here

python colorbar
1个回答
0
投票

我不确定我明白你的预期结果是什么。无论如何,我正在提供一个临时答案,这样你最终可以指出我正确的方向。这是使用numpy数组制作的示例颜色条:

enter image description here

我用来生成它的代码如下:

import numpy as np
import cv2

# Initialize an empty array that matches opencv ranges for hsv images:
#   hue (cylinder 180°) 0-179 (multiplied by 10 to "stretch" horizontally)
#   saturation is fixed at 254
#   value (0-254)
bar = np.ndarray([255,1800,3], dtype="uint8")
for x in range(1800):
    for y in range(255):
        bar[y,x,0] = int(x/10)
        bar[y,x,1] = 254
        bar[y,x,2] = y
#Convert to BGR (opencv standard instead of rgb)
bgr = cv2.cvtColor(bar, cv2.COLOR_HSV2BGR)
cv2.imshow('Colorbar', bgr)
cv2.waitKey()
© www.soinside.com 2019 - 2024. All rights reserved.