From 2ed10cdaf4896706fa9317fc5be3d50c549df67e Mon Sep 17 00:00:00 2001
From: ac <andrew.r.cohen@drexel.edu>
Date: Tue, 1 Aug 2023 13:37:37 -0400
Subject: [PATCH] SSF.quantize8 per channel

---
 matlab/+SSF/quantize8.m | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/matlab/+SSF/quantize8.m b/matlab/+SSF/quantize8.m
index 1a2a0f11..b367f475 100644
--- a/matlab/+SSF/quantize8.m
+++ b/matlab/+SSF/quantize8.m
@@ -4,11 +4,15 @@ function im = quantize8(im,clipLimits)
 if isa(im,'uint8')
     return
 end
-im = max(im,clipLimits(1));
-im = min(im,clipLimits(2));
 
-im = (im - clipLimits(1)) ./ (clipLimits(2) - clipLimits(1));
+for c = 1:size(im,4)
+    im(:,:,:,c) = max(im(:,:,:,c),clipLimits(c,1));
+    im(:,:,:,c) = min(im(:,:,:,c),clipLimits(c,2));
 
+    im(:,:,:,c) = (im(:,:,:,c) - clipLimits(c,1)) ./ (clipLimits(c,2) - clipLimits(c,1));
+    im(:,:,:,c) = im2uint8(im(:,:,:,c));
+    im(:,:,:,c) = max(im(:,:,:,c),1); % exclude 0 -- only for background
+    im(1,1,1,c) = 0; % must have at least one background...
+end
 im = im2uint8(im);
-im = max(im,1); % exclude 0 -- only for background
-im(1,1) = 0; % make sure at least 1 pixel hits background
\ No newline at end of file
+
-- 
GitLab