[atom feed]

2009-09-13

This is an excerpt from Jochen's blog.
Newer entry: paper accepted
Older entry: Sampling Conditioned Hypoelliptic Diffusions

77941 colorspace conversion in Python (updated)
2009-09-13

Just in case this is useful for anybody: here is an implementation of the HSV to RGB colorspace conversion in Python:

from __future__ import division

def hsv2rgb(h, s, v):
    hi = int(h//60 % 6)
    f = h/60 - h//60
    p = v * (1-s)
    q = v * (1-f*s)
    t = v * (1-(1-f)*s)
    return [ (v,t,p), (q,v,p), (p,v,t), (p,q,v), (t,p,v), (v,p,q) ][hi]

Update. In the meantime I learned that the Python standard library has a built-in version of this function in the colorsys module.

Creative Commons License

Copyright © 2011, Jochen Voss. All content on this website (including text, pictures, and any other original works), unless otherwise noted, is licensed under a Creative Commons Attribution-Share Alike 3.0 License.