From 3f345aa1904d0795f5726ed6a810245fda2d3639 Mon Sep 17 00:00:00 2001 From: ozbayb <17261091+ozbayb@users.noreply.github.com> Date: Sat, 24 Aug 2024 20:13:43 -0600 Subject: [PATCH] fix Image Levels Adjustment function to use mid_level --- WAS_Node_Suite.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/WAS_Node_Suite.py b/WAS_Node_Suite.py index 400ec98..cc346cc 100644 --- a/WAS_Node_Suite.py +++ b/WAS_Node_Suite.py @@ -6212,16 +6212,19 @@ class WAS_Image_Levels: def adjust(self, im): - im_arr = np.array(im) + im_arr = np.array(im).astype(np.float32) im_arr[im_arr < self.min_level] = self.min_level im_arr = (im_arr - self.min_level) * \ (255 / (self.max_level - self.min_level)) - im_arr[im_arr < 0] = 0 - im_arr[im_arr > 255] = 255 + im_arr = np.clip(im_arr, 0, 255) + + # mid-level adjustment + gamma = math.log(0.5) / math.log((self.mid_level - self.min_level) / (self.max_level - self.min_level)) + im_arr = np.power(im_arr / 255, gamma) * 255 + im_arr = im_arr.astype(np.uint8) im = Image.fromarray(im_arr) - im = ImageOps.autocontrast(im, cutoff=self.max_level) return im