【问题标题】:threshold_local returns a different result than threshold_adaptive in scikit-imagethreshold_local 返回的结果与 scikit-image 中的 threshold_adaptive 不同
【发布时间】:2018-09-02 17:00:49
【问题描述】:

我正在从文档中复制此 example

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 时,结果就不同了:

【问题讨论】:

  • @CrisLuengo 我的问题是如何在两种方法中获得相同的结果,因为它应该是相同的功能。我更新了代码

标签: python image-processing scikit-image threshold


【解决方案1】:

如果我们查看documentation for threshold_adaptive,我们会发现它已被弃用,取而代之的是新功能threshold_local。不幸的是,那个似乎没有记录。

我们仍然可以查看 older documentation 以了解 threshold_adaptive 的作用:它应用自适应阈值,生成二进制输出图像。

相比之下,未记录的threshold_local 不会返回二进制图像,正如您发现的那样。 Here is an example使用方法:

block_size = 35
adaptive_thresh = threshold_local(image, block_size, offset=10)
binary_adaptive = image > adaptive_thresh

发生了什么?

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

【讨论】:

    猜你喜欢
    • 2018-08-26
    • 2015-10-29
    • 1970-01-01
    • 2016-05-15
    • 2019-12-27
    • 2015-08-13
    • 1970-01-01
    • 1970-01-01
    • 2013-04-28
    相关资源
    最近更新 更多