def hsv2rgb(hsv_Nx3):
 hsv_Nx3 = numpy.asarray(hsv_Nx3, dtype=float)
 origShape = hsv_Nx3.shape
 hsv_Nx3 = hsv_Nx3.reshape([(-1), 3])
 H_ = ((hsv_Nx3[:, 0] % 360) / 60.0)
 C = (hsv_Nx3[:, 1] * hsv_Nx3[:, 2])
 X = (C * (1 - abs(((H_ % 2) - 1))))
 rgb = (hsv_Nx3 * 0)
 II = ((0 <= H_) * (H_ < 1))
 rgb[(II, 0)] = C[II]
 rgb[(II, 1)] = X[II]
 II = ((1 <= H_) * (H_ < 2))
 rgb[(II, 0)] = X[II]
 rgb[(II, 1)] = C[II]
 II = ((2 <= H_) * (H_ < 3))
 rgb[(II, 1)] = C[II]
 rgb[(II, 2)] = X[II]
 II = ((3 <= H_) * (H_ < 4))
 rgb[(II, 1)] = X[II]
 rgb[(II, 2)] = C[II]
 II = ((4 <= H_) * (H_ < 5))
 rgb[(II, 0)] = X[II]
 rgb[(II, 2)] = C[II]
 II = ((5 <= H_) * (H_ < 6))
 rgb[(II, 0)] = C[II]
 rgb[(II, 2)] = X[II]
 m = (hsv_Nx3[:, 2] - C)
 rgb += m.reshape([len(m), 1])
 return ((rgb.reshape(origShape) * 2) - 1)

def hsv2rgb ( hsv_Nx3 ) : hsv_Nx3 = numpy . asarray ( hsv_Nx3 , dtype = float ) origShape = hsv_Nx3 . shape hsv_Nx3 = hsv_Nx3 . reshape ( [ ( - 1 ) , 3 ] ) H_ = ( ( hsv_Nx3 [ : , 0 ] % 360 ) / 60.0 ) C = ( hsv_Nx3 [ : , 1 ] * hsv_Nx3 [ : , 2 ] ) X = ( C * ( 1 - abs ( ( ( H_ % 2 ) - 1 ) ) ) ) rgb = ( hsv_Nx3 * 0 ) II = ( ( 0 <= H_ ) * ( H_ < 1 ) ) rgb [ ( II , 0 ) ] = C [ II ] rgb [ ( II , 1 ) ] = X [ II ] II = ( ( 1 <= H_ ) * ( H_ < 2 ) ) rgb [ ( II , 0 ) ] = X [ II ] rgb [ ( II , 1 ) ] = C [ II ] II = ( ( 2 <= H_ ) * ( H_ < 3 ) ) rgb [ ( II , 1 ) ] = C [ II ] rgb [ ( II , 2 ) ] = X [ II ] II = ( ( 3 <= H_ ) * ( H_ < 4 ) ) rgb [ ( II , 1 ) ] = X [ II ] rgb [ ( II , 2 ) ] = C [ II ] II = ( ( 4 <= H_ ) * ( H_ < 5 ) ) rgb [ ( II , 0 ) ] = X [ II ] rgb [ ( II , 2 ) ] = C [ II ] II = ( ( 5 <= H_ ) * ( H_ < 6 ) ) rgb [ ( II , 0 ) ] = C [ II ] rgb [ ( II , 2 ) ] = X [ II ] m = ( hsv_Nx3 [ : , 2 ] - C ) rgb += m . reshape ( [ len ( m ) , 1 ] ) return ( ( rgb . reshape ( origShape ) * 2 ) - 1 )
hsv to rgb color space conversion .