【问题标题】:Load custom image from file system in scikit-image从 scikit-image 中的文件系统加载自定义图像
【发布时间】:2016-06-12 08:32:17
【问题描述】:

我是 Python 新手,我正在尝试学习官方页面上显示的教程。我的目标是使用 Local Otsu Threshold 方法分析我创建的图片。

带有示例图片的代码可以正常工作,但我想读取与*.py-file 存储在同一目录中的自定义图像。

这是代码:

from skimage import data
from skimage.morphology import disk
from skimage.filters import threshold_otsu, rank
from skimage.util import img_as_ubyte

import matplotlib
import matplotlib.pyplot as plt

matplotlib.rcParams['font.size'] = 9
img = img_as_ubyte(data.page())

radius = 15
selem = disk(radius)

local_otsu = rank.otsu(img, selem)
threshold_global_otsu = threshold_otsu(img)
global_otsu = img >= threshold_global_otsu

fig, ax = plt.subplots(2, 2, figsize=(8, 5), sharex=True, sharey=True,
                       subplot_kw={'adjustable': 'box-forced'})
ax0, ax1, ax2, ax3 = ax.ravel()

fig.colorbar(ax0.imshow(img, cmap=plt.cm.gray),
             ax=ax0, orientation='horizontal')
ax0.set_title('Original')
ax0.axis('off')

fig.colorbar(ax1.imshow(local_otsu, cmap=plt.cm.gray),
             ax=ax1, orientation='horizontal')
ax1.set_title('Local Otsu (radius=%d)' % radius)
ax1.axis('off')

ax2.imshow(img >= local_otsu, cmap=plt.cm.gray)
ax2.set_title('Original >= Local Otsu' % threshold_global_otsu)
ax2.axis('off')

ax3.imshow(global_otsu, cmap=plt.cm.gray)
ax3.set_title('Global Otsu (threshold = %d)' % threshold_global_otsu)
ax3.axis('off')

plt.show()

更具体地说,我想加载我的图像 example.jpg 而不是

img = img_as_ubyte(data.page())

我该怎么做?

【问题讨论】:

    标签: python image filesystems threshold scikit-image


    【解决方案1】:

    使用 skimage 库加载图像。

    如果没有安装:pip install -U scikit-image

    加载图片:

        from skimage import io
        img = io.imread('file_path')
    

    【讨论】:

      【解决方案2】:

      使用io.imread 函数

      img = io.imread('/path/to/example.jpg')
      

      【讨论】:

        猜你喜欢
        • 2014-07-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-03-16
        • 1970-01-01
        • 1970-01-01
        • 2019-12-09
        • 2017-10-01
        相关资源
        最近更新 更多