@@ -181,16 +181,35 @@ def Histogram1288(img, Qmax):
181181 ymin = np .min (y )
182182 ymax = np .max (y )
183183
184+ # Full distribution sigma, and mean
185+ full_mean = np .mean (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_mean - sigma5 ) & (y < full_mean + 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
187- Q = q + 1
203+ # Same for the Core
204+ q_core = ymax_core - ymin_core
205+ Q_core = q_core + 1
188206
189207 # When too many bins, create a new integer binwidth
190- if Q > Qmax :
208+ if Q_core > Qmax :
191209 # We want the number of bins as close as possible to Qmax (256)
192- W = int (np .ceil (1. * q / (Qmax - 1 )))
193- Q = int (np .floor (1. * q / W )) + 1
210+ W = int (np .ceil (1. * q_core / (Qmax - 1 )))
211+
212+ Q = int (np .floor (1. * q / W )) + 1
194213
195214 # The bins
196215 # we need one more value for the numpy histogram computation
@@ -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