【问题标题】:How to draw a HSV color wheel using matplotlib如何使用 matplotlib 绘制 HSV 色轮
【发布时间】:2020-06-23 09:40:41
【问题描述】:

是否可以在 python 中使用 matplotlib 绘制 HSV 色轮?我想得到一个像下图这样的 HSV 色轮作为光流的参考图像。在这张图片中,每种 HSV 颜色都可以表示为一个向量,其中方向以色调编码,长度以饱和度编码,以便我可以轻松地将其与光流进行比较。我在网上搜索过,但找不到满意的解决方案。任何帮助将不胜感激!

【问题讨论】:

    标签: python matplotlib colors hsv


    【解决方案1】:

    以下代码使用Colour 进行 HSV 到 RGB 的转换:

    def colour_wheel(samples=1024, clip_circle=True, method='Colour'):
        xx, yy = np.meshgrid(
            np.linspace(-1, 1, samples), np.linspace(-1, 1, samples))
    
        S = np.sqrt(xx ** 2 + yy ** 2)    
        H = (np.arctan2(xx, yy) + np.pi) / (np.pi * 2)
    
        HSV = colour.utilities.tstack([H, S, np.ones(H.shape)])
        RGB = colour.HSV_to_RGB(HSV)
    
        if clip_circle == True:
            RGB[S > 1] = 0
            A = np.where(S > 1, 0, 1)
        else:
            A = np.ones(S.shape)
    
        if method.lower()== 'matplotlib':
            RGB = colour.utilities.orient(RGB, '90 CW')
        elif method.lower()== 'nuke':
            RGB = colour.utilities.orient(RGB, 'Flip')
            RGB = colour.utilities.orient(RGB, '90 CW')
    
        R, G, B = colour.utilities.tsplit(RGB)
        
        return colour.utilities.tstack([R, G, B, A])
    

    我们在这个交互式 Jupyter Notebook Matplotlib Widget 中使用它:

    存储库在此处可用:https://github.com/colour-science/gamut-mapping-ramblings

    【讨论】:

      猜你喜欢
      • 2020-03-28
      • 2021-11-02
      • 1970-01-01
      • 2015-11-03
      • 1970-01-01
      • 1970-01-01
      • 2019-03-23
      • 2016-09-27
      • 2016-03-14
      相关资源
      最近更新 更多