Add threshold minimum algorithm

This commit is contained in:
Jeff Hemmelgarn
2015-07-18 09:06:50 -04:00
committed by François Boulogne
parent 71456ed672
commit 31db1c607e
4 changed files with 173 additions and 4 deletions
+37
View File
@@ -0,0 +1,37 @@
"""
==================================
Minimum Algorithm For Thresholding
==================================
The minimum algorithm takes a histogram of the image and smooths it
repeatedly unitl there are only two peaks in the histogram. Then it
finds the minimum value between the two peaks. With the smoothing
there can be multiple pixel values with the minimum histogram count,
so you can pick 'min', 'mid', or 'max' of these values.
"""
import matplotlib.pyplot as plt
from skimage import data
from skimage.filters.thresholding import threshold_minimum
image = data.camera()
threshold = threshold_minimum(image, bias='min')
binarized = image > threshold
fig, axes = plt.subplots(nrows=2, figsize=(7, 8))
ax0, ax1 = axes
plt.gray()
ax0.imshow(image)
ax0.set_title('Image')
ax1.imshow(binarized)
ax1.set_title('Thresholded')
for ax in axes:
ax.axis('off')
plt.show()