HSV to RGB Color Conversion

后端 未结 9 1684
离开以前
离开以前 2020-12-14 01:16

Is there a way to convert HSV color arguments to RGB type color arguments using pygame modules in python? I tried the following code, but it returns ridiculous values.

9条回答
  •  情深已故
    2020-12-14 01:35

    If you are working with Numpy arrays then matplotlib.colors.hsv_to_rgb is quite direct:

    import numpy as np
    from matplotlib.colors import hsv_to_rgb
    # This will create a nice image of varying hue and value
    hsv = np.zeros((512, 512, 3))
    hsv[..., 0] = np.linspace(0, 1, 512)
    hsv[..., 1] = 1.
    hsv[..., 2] = np.linspace(0, 1, 512)[:, np.newaxis]
    rgb = hsv_to_rgb(hsv)
    

    Note that the input and output images have values in the range [0, 1].

提交回复
热议问题