def rgb2hsv(rgb):
    """Converts RGB to HSV.

    Note that H may be None when S is 0 (for grey colors).
    """
    r, g, b = rgb
    minimum = min(r, g, b)
    maximum = max(r, g, b)

    v = maximum

    delta = maximum - minimum

    if delta != 0:
        s = delta / maximum
    else:
        # h is undefined
        s = 0
        h = None
        return (h, s, v)

    if r == maximum:
        h = (g - b) / delta     # between yellow & magenta
    elif g == maximum:
        h = 2 + (b - r) / delta # between cyan & yellow
    else:
        h = 4 + (r - g) / delta # between magenta & cyan

    h *= 60 # degrees

    if h < 0:
        h += 360

    return (h, s, v)