【问题标题】:Skimage imread returns img_arrayndarray; what are the properties?Skimage imread 返回 img_arrayndarray;有什么属性?
【发布时间】:2019-09-22 09:43:45
【问题描述】:

真的很惊讶,但我在img_arrayndarray 上找不到任何文档,这就是 skimage 的 imread 返回的内容。

https://scikit-image.org/docs/dev/api/skimage.io.html#skimage.io.imread

我的主要问题是这个对象有什么属性/方法等。

或者,文档如此缺乏是否有原因?例如,将 imread 转换为 numpy 数组是常见的做法吗?谢谢

【问题讨论】:

  • 这是一个已经修复的错误,这是因为 imread 现在返回他们自己的对象而不是 numpy 数组。在结果上调用np.asarray 以获得标准的NumPy 数组,或者现在使用io.imread(..., plugin='matplotlib') 或io.imread(..., plugin='pil') 来避免这个问题。这将在下一个版本中修复。
  • 谢谢,您的回答与下面的回答不一样吗?即imread 不返回标准 np 数组?
  • 我认为 Stéfan 误读了您的问题并与另一个错误混淆了。 imread 应该返回一个标准的 numpy ndarray。格式错误是由于最近的 sphinx 或 numpydoc 格式错误。正如warped在他的回答中指出的那样,它实际上是img_array : ndarray,ndarray 指的是numpy.ndarray。有关如何使用它们的信息,请参阅文档中的此页面:scikit-image.org/docs/dev/user_guide/numpy_images.html,有关 NumPy 数组的更多信息,请参阅 NumPy 文档:docs.scipy.org/doc/numpy-1.16.1

标签: python image computer-vision scikit-image vision


【解决方案1】:

测试功能,
使用 Python 2.7.13、Ipython 5.1.0、skimage 0.13.0、
和 Python 3.6.7、Ipython 7.4.0、skimage 0.15.0:

 In [1]: from skimage import io

 In [2]: a = io.imread('testimg.tif')

 In [3]: type(a)  
 Out[3]: numpy.ndarray

您的文档链接是 skimage 0.16.0,但我认为可以安全地假设文档中存在拼写错误。

编辑:另外,查看source:

def imread(fname, as_gray=False, plugin=None, flatten=None,
           **plugin_args):
    """Load an image from file.
    Parameters
    ----------
    fname : string
        Image file name, e.g. ``test.jpg`` or URL.
    as_gray : bool, optional
        If True, convert color images to gray-scale (64-bit floats).
        Images that are already in gray-scale format are not converted.
    plugin : str, optional
        Name of plugin to use.  By default, the different plugins are
        tried (starting with imageio) until a suitable
        candidate is found.  If not given and fname is a tiff file, the
        tifffile plugin will be used.
    Other Parameters
    ----------------
    plugin_args : keywords
        Passed to the given plugin.
    flatten : bool
        Backward compatible keyword, superseded by `as_gray`.
    Returns
    -------
    img_array : ndarray
        The different color bands/channels are stored in the
        third dimension, such that a gray-image is MxN, an
        RGB-image MxNx3 and an RGBA-image MxNx4.

【讨论】:

  • 谢谢!我也有一个问题,我尝试使用ndims 而不是ndim(正确的np),因此导致了这个问题。我会接受这个答案,等待上面评论中的跟进
【解决方案2】:

更多细节Stefan's answer:

scikit-image 没有在内部实现 IO 功能,而是将它们包装并委托给外部库(称为"plugings")。

您可以在此处查看支持的插件 - https://scikit-image.org/docs/dev/api/skimage.io.html,以及通过调用 skimage.io.find_available_plugins 可用于他或她自己的环境的插件。 插件按照特定的priority list 加载。

您看到的问题与其中一个插件中的 dtype 验证错误有关。最近,imageio 插件 (https://github.com/scikit-image/scikit-image/pull/3837) 修复了一个类似的错误,它将被合并到 0.14.3 (LTS)、0.15.1/0.16 (最新) 版本中。

【讨论】:

    猜你喜欢
    • 2020-09-19
    • 2014-11-15
    • 2021-03-19
    • 1970-01-01
    • 2013-02-27
    • 2018-09-16
    • 2021-12-17
    • 1970-01-01
    相关资源
    最近更新 更多