You need to determine the measure of similarity between the original image and the binary images, and then choose a threshold method that maximizes this measure.
Demo
, . , similarity , . .
import numpy as np
from skimage.data import text
import skimage.filters
import matplotlib.pyplot as plt
threshold_methods = [skimage.filters.threshold_otsu,
skimage.filters.threshold_yen,
skimage.filters.threshold_isodata,
skimage.filters.threshold_li,
skimage.filters.threshold_mean,
skimage.filters.threshold_minimum,
skimage.filters.threshold_mean,
skimage.filters.threshold_triangle,
]
def similarity(img, threshold_method):
"""Similarity measure between the original image img and and the
result of applying threshold_method to it.
"""
return np.random.random()
results = np.asarray([similarity(text(), f) for f in threshold_methods])
best_index = np.nonzero(results == results.min())[0][0]
best_method = thresholding_methods[best_index]
threshold = best_method(text())
binary = text() >= threshold
fig, ax = plt.subplots(1, 1)
ax.imshow(binary, cmap=plt.cm.gray)
ax.axis('off')
ax.set_title(best_method.__name__)
plt.show(fig)

, ( ). , . , , , , , , . , , , :
best_index = np.nonzero(results == results.min())[0][0]
.