【发布时间】:2019-07-18 22:26:15
【问题描述】:
我正在试用 Scikit Image 网站上提供的示例 Python 脚本之一。此脚本演示了本地级别的 Otsu 分割。该脚本适用于使用
加载的图片data.page()
但不使用
io.imread
。有什么建议吗?
图片文件
实际输出 - 局部阈值窗口为空
如您所见,全局阈值处理有效。但局部阈值处理未能产生任何结果。
奇怪的是,如果我使用 data.page() 那么一切正常。
脚本
from skimage import io
from skimage.color import rgb2gray
import matplotlib.pyplot as plt
from skimage.filters import threshold_otsu,threshold_local
import matplotlib
from skimage import data
from skimage.util import img_as_ubyte
filename="C:\\Lenna.png"
mypic= img_as_ubyte (io.imread(filename))
#image = data.page() #This works - why not io.imread ?
imagefromfile=io.imread(filename)
image = rgb2gray(imagefromfile)
global_thresh = threshold_otsu(image)
binary_global = image > global_thresh
block_size = 35
local_thresh = threshold_local(image, block_size, offset=10)
binary_local = image > local_thresh
fig, axes = plt.subplots(nrows=3, figsize=(7, 8))
ax = axes.ravel()
plt.gray()
ax[0].imshow(image)
ax[0].set_title('Original')
ax[1].imshow(binary_global)
ax[1].set_title('Global thresholding')
ax[2].imshow(binary_local)
ax[2].set_title('Local thresholding')
for a in ax:
a.axis('off')
plt.show()
【问题讨论】:
标签: scikit-image