Compare commits

..

2 Commits

Author SHA1 Message Date
6a2958a68b Added normalfunc calcs 2023-09-29 15:14:24 +02:00
28a1123bab Added distribution.py 2023-09-29 15:14:12 +02:00
2 changed files with 55 additions and 1 deletions

View File

@ -0,0 +1,37 @@
import numpy as np
import matplotlib.pyplot as plt
import math
mean = 125
sd = 20
N = 255
f = np.zeros(N, dtype=np.longdouble)
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
f = calcNormalFunc(mean, sd, N)
plt.title("PDF: $\mu = %d$, $\sigma = %d$"%(mean, sd))
plt.plot(f)
plt.grid()
plt.xlim(0, 255)
plt.ylim(0, 1.05)
plt.show()
print("Score at 1 sigma: %f"%f[sd+mean])
print("Score at 2 sigma: %f"%f[2*sd+mean])
print("Score at 3 sigma: %f"%f[3*sd+mean])

View File

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