From 9c9d359966ef53af118334a3391a6c621be28378 Mon Sep 17 00:00:00 2001 From: Ateendra Gaur Date: Mon, 17 Apr 2023 21:18:42 +0530 Subject: [PATCH] Update to_8U function in image.py It generates most of the images black. this modification will rectify that --- cv/image.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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)