2023-09-25 14:57:34 +02:00
|
|
|
import numpy as np
|
2023-09-29 15:14:24 +02:00
|
|
|
import math
|
2023-09-25 14:57:34 +02:00
|
|
|
|
|
|
|
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])
|
2023-09-29 15:14:24 +02:00
|
|
|
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
|