Logarithm optimisation

This commit is contained in:
radioxoma
2013-09-07 19:10:40 +03:00
committed by radioxoma
parent 9e74f4eb70
commit 04804cc81c
+3 -3
View File
@@ -1,4 +1,4 @@
__all__ = ['threshold_adaptive', 'threshold_otsu', 'threshold_yen']
__all__ = ['threshold_otsu', 'threshold_adaptive', 'threshold_yen']
import numpy as np
import scipy.ndimage
@@ -179,8 +179,8 @@ def threshold_yen(image, nbins=256):
P2_sq = np.cumsum(norm_histo[::-1] ** 2)[::-1]
# P2_sq indexes is shifted +1. I assume, with P1[:-1] it's help avoid '-inf'
# in crit. ImageJ Yen implementation replaces those values by zero.
crit = -1 * np.log(P1_sq[:-1] * P2_sq[1:]) + \
2.0 * np.log(P1[:-1] * (1.0 - P1[:-1]))
crit = np.log(((P1_sq[:-1] * P2_sq[1:]) ** -1) * \
(P1[:-1] * (1.0 - P1[:-1])) ** 2)
max_crit = np.argmax(crit)
threshold = bin_centers[:-1][max_crit]
return threshold