Skip to content

Commit 9eff37b

Browse files
author
Charles Authier
committed
change on histogram for extern value dot affect the definition
1 parent 31b83bf commit 9eff37b

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

emva1288/process/routines.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,34 @@ def Histogram1288(img, Qmax):
181181
ymin = np.min(y)
182182
ymax = np.max(y)
183183

184+
# Full distribution sigma, and median
185+
full_median = np.median(y)
186+
full_sigma = np.std(y)
187+
# with 5 sigma, 99.9999426697% values are in the Normal distribution
188+
# Source: Wikipedia, Normal distribution, section on standart diviation
189+
sigma5 = full_sigma * 5
190+
# Core, main distribution
191+
core = y[(y > full_median - sigma5) & (y < full_median + sigma5)]
192+
# Normal distribution with the original sigma, and mean
193+
mu = np.mean(core)
194+
sigma = np.std(core)
195+
196+
# Core ymin and ymax
197+
ymin_core = np.min(core)
198+
ymax_core = np.max(core)
199+
184200
# Because we are working with integers, minimum binwidth is 1
185201
W = 1
186202
q = ymax - ymin
187203
Q = q + 1
204+
# Same for the Core
205+
q_core = ymax_core - ymin_core
206+
Q_core = q_core + 1
188207

189208
# When too many bins, create a new integer binwidth
190-
if Q > Qmax:
209+
if Q_core > Qmax:
191210
# We want the number of bins as close as possible to Qmax (256)
192-
W = int(np.ceil(1. * q / (Qmax - 1)))
211+
W = int(np.ceil(1. * q_core / (Qmax - 1)))
193212
Q = int(np.floor(1. * q / W)) + 1
194213

195214
# The bins
@@ -199,8 +218,6 @@ def Histogram1288(img, Qmax):
199218
B = [ymin + (i * W) for i in range(Q + 1)]
200219

201220
# Normal distribution with the original sigma, and mean
202-
mu = np.mean(y)
203-
sigma = np.std(y)
204221
normal = ((1. * (ymax - ymin) / Q) *
205222
np.size(y) / (np.sqrt(2 * np.pi) * sigma) *
206223
np.exp(-0.5 * (1. / sigma * (B[:-1] - mu)) ** 2))

0 commit comments

Comments
 (0)