diff base/ColumnOp.cpp @ 1394:9ef1cc26024c

Add Range01 normalisation method to ColumnOp. This is the normalisation that is actually used in the Colour 3D Plot layer historically when column normalisation is enabled (not Max1 after all).
author Chris Cannam
date Tue, 28 Feb 2017 14:04:16 +0000
parents 47ee4706055c
children 1b688ab5f1b3
line wrap: on
line diff
--- a/base/ColumnOp.cpp	Tue Feb 28 11:26:24 2017 +0000
+++ b/base/ColumnOp.cpp	Tue Feb 28 14:04:16 2017 +0000
@@ -49,10 +49,33 @@
     if (n == ColumnNormalization::None || in.empty()) {
         return in;
     }
+    
+    float shift = 0.f;
+    float scale = 1.f;
 
-    float scale = 1.f;
-        
-    if (n == ColumnNormalization::Sum1) {
+    if (n == ColumnNormalization::Range01) {
+
+        float min = 0.f;
+        float max = 0.f;
+        bool have = false;
+        for (auto v: in) {
+            if (v < min || !have) {
+                min = v;
+            }
+            if (v > max || !have) {
+                max = v;
+            }
+            have = true;
+        }
+        if (min != 0.f) {
+            shift = -min;
+            max -= min;
+        }
+        if (max != 0.f) {
+            scale = 1.f / max;
+        }
+
+    } else if (n == ColumnNormalization::Sum1) {
 
         float sum = 0.f;
 
@@ -86,7 +109,7 @@
         }
     }
 
-    return applyGain(in, scale);
+    return applyGain(applyShift(in, shift), scale);
 }
 
 ColumnOp::Column