This threshold function based on [Sezgin M. and Sankur B. (2004) "Survey over Image Thresholding Techniques and Quantitative Performance Evaluation](http://www.busim.ee.boun.edu.tr/~sankur/SankurFolder/Threshold_survey.pdf) paper (page 150, Cluster_Riddler). Original notation uses probability mass function (pmf) for many thresholding techniques but in this case it is not necessary (cause `hist.sum()` reduced in fraction).

I leave this comment for educational / explanation purposes. You can uncomment this line and function still work nice.