簡體   English   中英

我可以用簡單的方法轉換 RGB > HSV 嗎?

[英]Can I Convert RGB > HSV the simple way?

好的。 我正在創建一個色盲模擬器。 我正在開發一個測試版,您只需在 HSV/HSB 中插入顏色的屬性,而不是整個圖像。

h = input('Hue: ');
s = input('Saturation: ');
v = input('Value/Brightness: ');

但是,我需要一個可以將 HSV/HSB 轉換為 RGB 的算法或方程式。 我已經嘗試了很多東西,但我花的大部分時間都在研究 python 無法使用的算法,並嘗試將它們轉換為 python 可以理解的算法。 所以,我只想要一個簡單、漂亮的算法,如果你不知道它是如何工作的也沒關系; 但是,求求您。 如果我可以轉換 RGB > HSV,並且兩者都沒有任何導入,那也很好。 此外,是否必須將 HSV 替換為 HSL 也沒有關系。

顏色工具Machado、Oliveira 和 Fernandes (2009)色覺缺陷 (CVD) model:

H = 0 # input('Hue: ')
S = 0.95 # input('Saturation: ')
V = 0.75 # input('Value/Brightness: ')
deficiency = 'Protanomaly' # input('Deficiency (Protanomaly, Deuteranomaly, Tritanomaly)')
severity = 0.75 # input('Severity [0, 1]')

# Assuming linear H, S, V input.
HSV = [H, S, V]

RGB = colour.cctf_decoding(colour.HSV_to_RGB(HSV))
M_a = colour.blindness.matrix_cvd_Machado2009(deficiency, severity)
RGB_a = colour.utilities.vector_dot(M_a, RGB)

colour.plotting.plot_multi_colour_swatches(colour.cctf_encoding([RGB, RGB_a]));

CVD色板

對於色輪:

def colour_wheel(samples=512, 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

    if method.lower()== 'nuke':
        RGB = colour.utilities.orient(RGB, 'Flip')
        RGB = colour.utilities.orient(RGB, '90 CW')

    return RGB


colour.plotting.plot_image(colour.cctf_encoding(
    colour_wheel()));

colour.plotting.plot_image(colour.cctf_encoding(
    colour.utilities.vector_dot(M_a, colour_wheel())));

色輪 色輪 - CVD

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM