diff --git a/cv/image.py b/cv/image.py index d923f5c..3a058ef 100644 --- a/cv/image.py +++ b/cv/image.py @@ -10,6 +10,12 @@ def to_32F(image): def to_8U(image): if image.max() <= 1.0: image = image * 255.0 - return np.clip(np.uint8(image), 0, 255) + else: + image = image.astype(np.float32) + range_min = np.min(image) + range_max = np.max(image) + if range_max > range_min: + image = (image - range_min) * (255.0 / (range_max - range_min)) + return np.clip(np.round(image).astype(np.uint8), 0, 255)