From e0c1f862ca0fa23ab985816e800f494d81e5820e Mon Sep 17 00:00:00 2001
From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch>
Date: Tue, 31 Jul 2018 17:43:49 +0200
Subject: [PATCH] Ensure to convert to 8-bit in a reasonable fashion

Unlike what we had assumed, the "resetMinAndMax()" command doesn't set the
display range to min and max of the current bit depth but rather to the min and
max from the actual values. This was causing a high offset (many pixels with
value zero) after converting to 8 bit, so we rather calculate the display range
now from the actual values before converting to 8-bit.
---
 .../scripts/Plugins/NoiSee/NoiSee_Bead_Analysis.ijm      | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/main/resources/scripts/Plugins/NoiSee/NoiSee_Bead_Analysis.ijm b/src/main/resources/scripts/Plugins/NoiSee/NoiSee_Bead_Analysis.ijm
index c021f2c..c1bb1d7 100644
--- a/src/main/resources/scripts/Plugins/NoiSee/NoiSee_Bead_Analysis.ijm
+++ b/src/main/resources/scripts/Plugins/NoiSee/NoiSee_Bead_Analysis.ijm
@@ -549,7 +549,14 @@ function process_beads() {
     print("processing image: " + fname + "  (location: [" + fpath + "])");
     if (bitDepth() > 8) {
         print("image type " +  bitDepth() + " bit detected, converting to 8 bit...");
-        resetMinAndMax();
+        Stack.getStatistics(_, _, stack_min, stack_max, _);
+        new_max = stack_max * 1.1;
+        // NOTE: having a new value larger than the max value of the current bit
+        // depth is unproblematic since ImageJ apparently just uses the maximum
+        // possible value then:
+        print("setting display range min/max to 0/" + new_max + " (was: " +
+            stack_min + "/" + stack_max + ")");
+        setMinAndMax(0, new_max);
         run("8-bit");
     }
 
-- 
GitLab