From 204defad86eb248da71decbc1d4a60486fabb033 Mon Sep 17 00:00:00 2001 From: ac_fx <arc334@drexel.edu> Date: Fri, 10 Nov 2023 11:16:22 -0500 Subject: [PATCH] SSF equiprobable quantization --- matlab/+SSF/getClipLimits.m | 38 +++++++++++++++++++++---------------- matlab/+SSF/quantize8.m | 16 ++++++++++------ 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/matlab/+SSF/getClipLimits.m b/matlab/+SSF/getClipLimits.m index 423e8329..dc177d9e 100644 --- a/matlab/+SSF/getClipLimits.m +++ b/matlab/+SSF/getClipLimits.m @@ -13,6 +13,7 @@ if ~exist('tClip','var') end p = ljsStartParallel(); kymoPixels = {}; +clipLimits = {}; parfor ff=1:length(flist) kp = {}; for c = 1:length(targetChannelNumbers) @@ -25,22 +26,27 @@ parfor ff=1:length(flist) im_ff(im_ff>0)=0; im_ff = abs(im_ff); end - kp{c} = im_ff(find(im_ff)); - kymoPixels{ff} = kp; - end -end -kymoPixels = vertcat(kymoPixels{:}); + px = im_ff(find(im_ff)); + kymoPixels{ff} = px; -clipLimits = []; -for c = 1:size(kymoPixels,2) - % anything other than [0,1] gets set to the corresponding percentile - idx = find(clipRange); - if ~isempty(idx) - px = kymoPixels{:,c}; - clipLimits(c,idx) = [prctile(px,clipRange(idx))]; - end - clipLimits(c,find(clipRange==0)) = 0; -end +% clipLimits{ff} = [mean(px)-std(px),mean(px)+std(px)]; %prctile(kp{c},[0.5,99.5]); + clipLimits{ff} = prctile(px,100.*[1/255:1/255:1-1/255]); + end +end +% kymoPixels = vertcat(kymoPixels{:}); +% clipLimits = prctile(kymoPixels,100.*[1/255:1/255:1-1/255]); -4; \ No newline at end of file +% clipLimits = []; +% for c = 1:size(kymoPixels,2) +% % anything other than [0,1] gets set to the corresponding percentile +% idx = find(clipRange); +% if ~isempty(idx) +% px = kymoPixels{:,c}; +% clipLimits(c,idx) = [mean(px)-std(px),mean(px)+std(px)]; %[prctile(px,clipRange(idx))]; +% end +% clipLimits(c,find(clipRange==0)) = 0; +% end +% +% +% 4; \ No newline at end of file diff --git a/matlab/+SSF/quantize8.m b/matlab/+SSF/quantize8.m index 7feb548d..1dbd08aa 100644 --- a/matlab/+SSF/quantize8.m +++ b/matlab/+SSF/quantize8.m @@ -5,11 +5,15 @@ im = im_in; if isa(im,'uint8') return end -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)); -end -im = im2uint8(im); + +im = uint8(imquantize(im,clipLimits)); +% +% 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)); +% end +% im = im2uint8(im); + im = max(im,1); im(0 == im_in) = 0; \ No newline at end of file -- GitLab