Compare commits
2 Commits
89001d47a0
...
6a2958a68b
Author | SHA1 | Date | |
---|---|---|---|
6a2958a68b | |||
28a1123bab |
37
src/experiments/algorithms/distribution.py
Normal file
37
src/experiments/algorithms/distribution.py
Normal 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])
|
@ -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
|
Loading…
Reference in New Issue
Block a user