EV5_Beeldherk_Bomen/src/helpers/statistics.py

26 lines
617 B
Python

import numpy as np
import math
def imgStats(img):
mean = np.zeros(3)
std = np.zeros(3)
for i in range(img.shape[2]):
mean[i] = np.mean(img[:, :, i])
std[i] = np.std(img[:, :, i])
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