comparison 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
comparison
equal deleted inserted replaced
1393:04abe8f73b22 1394:9ef1cc26024c
47 ColumnOp::normalize(const Column &in, ColumnNormalization n) { 47 ColumnOp::normalize(const Column &in, ColumnNormalization n) {
48 48
49 if (n == ColumnNormalization::None || in.empty()) { 49 if (n == ColumnNormalization::None || in.empty()) {
50 return in; 50 return in;
51 } 51 }
52 52
53 float shift = 0.f;
53 float scale = 1.f; 54 float scale = 1.f;
54 55
55 if (n == ColumnNormalization::Sum1) { 56 if (n == ColumnNormalization::Range01) {
57
58 float min = 0.f;
59 float max = 0.f;
60 bool have = false;
61 for (auto v: in) {
62 if (v < min || !have) {
63 min = v;
64 }
65 if (v > max || !have) {
66 max = v;
67 }
68 have = true;
69 }
70 if (min != 0.f) {
71 shift = -min;
72 max -= min;
73 }
74 if (max != 0.f) {
75 scale = 1.f / max;
76 }
77
78 } else if (n == ColumnNormalization::Sum1) {
56 79
57 float sum = 0.f; 80 float sum = 0.f;
58 81
59 for (auto v: in) { 82 for (auto v: in) {
60 sum += fabsf(v); 83 sum += fabsf(v);
84 scale = log10f(max + 1.f) / max; 107 scale = log10f(max + 1.f) / max;
85 } 108 }
86 } 109 }
87 } 110 }
88 111
89 return applyGain(in, scale); 112 return applyGain(applyShift(in, shift), scale);
90 } 113 }
91 114
92 ColumnOp::Column 115 ColumnOp::Column
93 ColumnOp::distribute(const Column &in, 116 ColumnOp::distribute(const Column &in,
94 int h, 117 int h,