def set_color(img, coords, color, alpha=1):
 (rr, cc) = coords
 if (img.ndim == 2):
  img = img[..., np.newaxis]
 color = np.array(color, ndmin=1, copy=False)
 if (img.shape[(-1)] != color.shape[(-1)]):
  raise ValueError('Color shape ({}) must match last image dimension ({}).'.format(color.shape[0], img.shape[(-1)]))
 if np.isscalar(alpha):
  alpha = (np.ones_like(rr) * alpha)
 (rr, cc, alpha) = _coords_inside_image(rr, cc, img.shape, val=alpha)
 alpha = alpha[..., np.newaxis]
 color = (color * alpha)
 vals = (img[(rr, cc)] * (1 - alpha))
 img[(rr, cc)] = (vals + color)

def set_color ( img , coords , color , alpha = 1 ) : ( rr , cc ) = coords if ( img . ndim == 2 ) : img = img [ ... , np . newaxis ] color = np . array ( color , ndmin = 1 , copy = False ) if ( img . shape [ ( - 1 ) ] != color . shape [ ( - 1 ) ] ) : raise ValueError ( 'Color shape ({}) must match last image dimension ({}).' . format ( color . shape [ 0 ] , img . shape [ ( - 1 ) ] ) ) if np . isscalar ( alpha ) : alpha = ( np . ones_like ( rr ) * alpha ) ( rr , cc , alpha ) = _coords_inside_image ( rr , cc , img . shape , val = alpha ) alpha = alpha [ ... , np . newaxis ] color = ( color * alpha ) vals = ( img [ ( rr , cc ) ] * ( 1 - alpha ) ) img [ ( rr , cc ) ] = ( vals + color )
set pixel color in the image at the given coordinates .