我正在从文档中复制这个示例:
import matplotlib.pyplot as plt
from skimage import data
from skimage.filters import threshold_otsu, threshold_adaptive
image = data.page()
global_thresh = threshold_otsu(image)
binary_global = image > global_thresh
block_size = 35
binary_adaptive = threshold_adaptive(image, block_size, offset=10)
fig, axes = plt.subplots(nrows=3, figsize=(7, 8))
ax0, ax1, ax2 = axes
plt.gray()
ax0.imshow(image)
ax0.set_title('Image')
ax1.imshow(binary_global)
ax1.set_title('Global thresholding')
ax2.imshow(binary_adaptive)
ax2.set_title('Adaptive thresholding')
for ax in axes:
ax.axis('off')
plt.show()这里有threshold_adaptive,但是它会引发一个警告:

UserWarning:threshold_local的返回值是阈值图像,而threshold_adaptive返回阈值图像
但是,当我使用threshold_adaptive时,结果是不同的:

发布于 2018-03-24 20:17:46
如果我们看一下threshold_adaptive,我们就会发现它已经被废弃,转而支持一个新的函数threshold_local。不幸的是,这一条似乎没有被记录下来。
我们仍然可以通过查看旧文档来了解threshold_adaptive所做的事情:它应用一个自适应阈值,生成一个二进制输出图像。
相反,没有文档的threshold_local不会返回二进制图像,正如您所发现的那样。关于如何使用它的下面是一个例子:
block_size = 35
adaptive_thresh = threshold_local(image, block_size, offset=10)
binary_adaptive = image > adaptive_thresh这是怎么回事?
该函数为每个像素计算一个阈值。但是它不是直接应用这个阈值,而是返回包含所有这些阈值的图像。将原始图像与阈值图像进行比较是应用阈值的方法,产生二值图像。
https://stackoverflow.com/questions/49459459
复制相似问题