首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >threshold_local返回与threshold_adaptive不同的结果

threshold_local返回与threshold_adaptive不同的结果
EN

Stack Overflow用户
提问于 2018-03-23 23:10:56
回答 1查看 3.5K关注 0票数 4

我正在从文档中复制这个示例

代码语言:javascript
复制
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时,结果是不同的:

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-24 20:17:46

如果我们看一下threshold_adaptive,我们就会发现它已经被废弃,转而支持一个新的函数threshold_local。不幸的是,这一条似乎没有被记录下来。

我们仍然可以通过查看旧文档来了解threshold_adaptive所做的事情:它应用一个自适应阈值,生成一个二进制输出图像。

相反,没有文档的threshold_local不会返回二进制图像,正如您所发现的那样。关于如何使用它的下面是一个例子

代码语言:javascript
复制
block_size = 35
adaptive_thresh = threshold_local(image, block_size, offset=10)
binary_adaptive = image > adaptive_thresh

这是怎么回事?

该函数为每个像素计算一个阈值。但是它不是直接应用这个阈值,而是返回包含所有这些阈值的图像。将原始图像与阈值图像进行比较是应用阈值的方法,产生二值图像。

票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49459459

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档