Last active
November 8, 2018 08:32
-
-
Save princewang1994/082b7e144179e6feb9b3d5bceca516f9 to your computer and use it in GitHub Desktop.
在python中使用OSTU算法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 在python中使用OSTU算法 | |
import matplotlib.pyplot as plt | |
from skimage import data | |
try: | |
from skimage import filters | |
except ImportError: | |
from skimage import filter as filters | |
from skimage import exposure | |
camera = data.camera() | |
val = filters.threshold_otsu(camera) | |
hist, bins_center = exposure.histogram(camera) | |
plt.figure(figsize=(9, 4)) | |
plt.subplot(131) | |
plt.imshow(camera, cmap='gray', interpolation='nearest') | |
plt.axis('off') | |
plt.subplot(132) | |
plt.imshow(camera < val, cmap='gray', interpolation='nearest') | |
plt.axis('off') | |
plt.subplot(133) | |
plt.plot(bins_center, hist, lw=2) | |
plt.axvline(val, color='k', ls='--') | |
plt.tight_layout() | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment