From bf43eae88b786cf8e397fef9ad7d39eb32b99c84 Mon Sep 17 00:00:00 2001
From: Carl Klemm <carl@uvos.xyz>
Date: Mon, 2 May 2022 15:59:40 +0200
Subject: [PATCH] Normalize: use median for reduceRegion

---
 normalize.cpp | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/normalize.cpp b/normalize.cpp
index b70f87a..c5f57eb 100644
--- a/normalize.cpp
+++ b/normalize.cpp
@@ -52,17 +52,14 @@ std::vector<eis::DataPoint> eis::reduceRegion(const std::vector<eis::DataPoint>&
 
 	std::vector<fvalue> grads;
 	grads.reserve(data.size());
-	fvalue meanGrad = 0;
 	eis::Log(eis::Log::DEBUG)<<"Grads:";
 	for(size_t i = 0; i < data.size(); ++i)
 	{
 		grads.push_back(std::abs(eis::absGrad(data, i)));
-		meanGrad += grads.back();
 		eis::Log(eis::Log::DEBUG)<<i<<": "<<inData[i].omega<<','<<grads.back();
 	}
 
-	meanGrad = meanGrad / grads.size();
-	fvalue gradThresh = meanGrad*gradThreshFactor;
+	fvalue gradThresh = eis::median(grads)*gradThreshFactor;
 
 	eis::Log(eis::Log::DEBUG)<<"Grad thresh is:"<<','<<gradThresh;
 
-- 
GitLab