From baae40684b0173367bd3b13e578b10c31c8acc90 Mon Sep 17 00:00:00 2001
From: monadal <morgane.nadal@inria.fr>
Date: Tue, 10 Mar 2020 11:12:55 +0100
Subject: [PATCH] wrote fct for relative intensity image normalization +
 refractoring

---
 brick/general/feedback.py |  8 ++++----
 brick/processing/input.py | 32 ++++++++++++++++++++++----------
 nutrimorph.py             |  4 ++--
 3 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/brick/general/feedback.py b/brick/general/feedback.py
index a0973cc..814a05e 100644
--- a/brick/general/feedback.py
+++ b/brick/general/feedback.py
@@ -57,10 +57,10 @@ def PlotSomas(somas: Sequence[soma_t], som_nfo: dict, axes: dict) -> None:
     for soma in somas:
         axes[soma.uid] = ot_.PlotLMap(som_nfo["lmp"], labels=soma.uid)
         pl_.title(f"Soma.{soma.uid}")
-    pl_.matshow(som_nfo["influence_map"].max(axis=0)), pl_.title("Soma Influencess")
-    pl_.show(block=True)
-    pl_.matshow(som_nfo["dist_to_closest"].max(axis=0)), pl_.title("Soma Distances")
-    pl_.show(block=True)
+    # pl_.matshow(som_nfo["influence_map"].max(axis=0)), pl_.title("Soma Influencess")
+    # pl_.show(block=True)
+    # pl_.matshow(som_nfo["dist_to_closest"].max(axis=0)), pl_.title("Soma Distances")
+    # pl_.show(block=True)
 
 
 def PlotExtensions(
diff --git a/brick/processing/input.py b/brick/processing/input.py
index b0bb8f1..a9a1a11 100644
--- a/brick/processing/input.py
+++ b/brick/processing/input.py
@@ -68,21 +68,33 @@ def ImageVerification(image, channel):
 #     print('WARNING. The 3 RGB color channels were selected in the parameters but the image has only one channel.')
 
 
-def NormalizedImage(image: array_t) -> array_t:
+def IntensityNormalizedImage(image: array_t) -> array_t:
     #
-    print(
-        "This normalization does not bring anything; left as is for now to avoid the need for changing prms"
-    )
-    nonextreme_values = image[np_.logical_and(image > 0.0, image < image.max())]
+    print('Relative Intensity Normalization between 0 and 1 (Not a standardization). Need to reevaluate the parameters !!!')
 
-    if nonextreme_values.size > 0:
-        nonextreme_avg = nonextreme_values.mean()
-        result = image.astype(np_.float32) / nonextreme_avg
-    else:
-        result = image.astype(np_.float32)
+    value_max = image.astype(np_.float32).max()
+    value_min = image.astype(np_.float32).min()
+
+    result = (image.astype(np_.float32) - value_min)/(value_max - value_min)
 
     return result
 
+    # print(
+    #     "This normalization does not bring anything; left as is for now to avoid the need for changing prms"
+    # )
+    # nonextreme_values = image[np_.logical_and(image > 0.0, image < image.max())]
+    #
+    # if nonextreme_values.size > 0:
+    #     nonextreme_avg = nonextreme_values.mean()
+    #     result = image.astype(np_.float32) / nonextreme_avg
+    # else:
+    #     result = image.astype(np_.float32)
+    #
+    # return result
+
+def MetricNormalizedImage(image: array_t) -> array_t:  # TODO
+    #
+    print('Image metric in converted to micrometers.')
 
 def DijkstraCosts(image: array_t, som_map: array_t, ext_map: array_t) -> array_t:
     #
diff --git a/nutrimorph.py b/nutrimorph.py
index 3df86f9..ca15e44 100644
--- a/nutrimorph.py
+++ b/nutrimorph.py
@@ -106,8 +106,8 @@ img_shape = image.shape
 #
 print(f"IMAGE: s.{img_shape} t.{image.dtype} m.{image.min()} M.{image.max()}")
 
-image_for_soma = in_.NormalizedImage(image)
-image_for_ext = in_.NormalizedImage(image)
+image_for_soma = in_.IntensityNormalizedImage(image)
+image_for_ext = in_.IntensityNormalizedImage(image)
 print(f"NRM-IMG: t.{image_for_soma.dtype} m.{image_for_soma.min():.2f} M.{image_for_soma.max():.2f}")
 
 # --- Initialization
-- 
GitLab