From 6a2958a68b1f90c8ca974179022c58c4d3696dd1 Mon Sep 17 00:00:00 2001 From: Tom Selier Date: Fri, 29 Sep 2023 15:14:24 +0200 Subject: [PATCH] Added normalfunc calcs --- src/helpers/statistics.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/helpers/statistics.py b/src/helpers/statistics.py index c92e061..176670e 100644 --- a/src/helpers/statistics.py +++ b/src/helpers/statistics.py @@ -1,4 +1,5 @@ import numpy as np +import math def imgStats(img): mean = np.zeros(3) @@ -6,4 +7,20 @@ def imgStats(img): for i in range(img.shape[2]): mean[i] = np.mean(img[:, :, i]) std[i] = np.std(img[:, :, i]) - return mean, std \ No newline at end of file + return mean, std + +def calcNormalFunc(mean, sd, len): + f = np.zeros(len, dtype=np.longdouble) + + # calculate PDF + for x in range(len): + exp = (-(x - mean) ** 2)/(2 * sd ** 2) + f[x] = 1 / math.sqrt(2 * np.pi * sd** 20 ) * (math.exp(exp)) + + # normalize PDF + max = np.amax(f) + min = np.amin(f) + for x in range(len): + f[x] = (f[x] - min) / (max - min) + + return f \ No newline at end of file