def smooth_with_function_and_mask(image, function, mask):
 bleed_over = function(mask.astype(float))
 masked_image = np.zeros(image.shape, image.dtype)
 masked_image[mask] = image[mask]
 smoothed_image = function(masked_image)
 output_image = (smoothed_image / (bleed_over + np.finfo(float).eps))
 return output_image

def smooth_with_function_and_mask ( image , function , mask ) : bleed_over = function ( mask . astype ( float ) ) masked_image = np . zeros ( image . shape , image . dtype ) masked_image [ mask ] = image [ mask ] smoothed_image = function ( masked_image ) output_image = ( smoothed_image / ( bleed_over + np . finfo ( float ) . eps ) ) return output_image
smooth an image with a linear function .