def to_8U(image): if image.max() <= 1.0: image = image * 255.0 return np.clip(np.uint8(image), 0, 255)