Lui*_*uez 3 python image-processing threshold scikit-image
我正在从文档中复制此示例:
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()
Run Code Online (Sandbox Code Playgroud)
有threshold_adaptive,但是会引发警告:
“用户警告:的返回值为threshold_local阈值图像,而threshold_adaptive返回的是阈值图像”
但是当我使用threshold_adaptive时,结果是不同的:
如果我们查看相关文档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
Run Code Online (Sandbox Code Playgroud)
怎么了?
该函数为每个像素计算阈值。但是,它不会直接应用该阈值,而是返回包含所有这些阈值的图像。将原始图像与阈值图像进行比较是应用阈值的方法,从而生成二进制图像。