首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python `filter.sobel()`输入

Python `filter.sobel()`输入
EN

Stack Overflow用户
提问于 2014-08-26 06:18:48
回答 1查看 1.1K关注 0票数 0

尝试使用Python语言中的filter.sobel()函数。

代码语言:javascript
复制
from PIL import Image
from skimage import data, io, filter
#...

image = Image.open('ME.jpg')
#right below is what it would normally be. I tried to substitute the code above for this
#image = data.coins()
edges = filter.sobel(image)
io.imshow(image)
io.show()
io.imshow(edges)
io.show()

o/p:

代码语言:javascript
复制
Traceback (most recent call last):
 File "edg.py", line 7, in <module>
    edges = filter.sobel(image)
  File "/Library/Python/2.7/site-packages/skimage/filter/edges.py", line 83, in sobel
    return np.sqrt(hsobel(image, mask)**2 + vsobel(image, mask)**2)
  File "/Library/Python/2.7/site-packages/skimage/filter/edges.py", line 114, in hsobel
    result = np.abs(convolve(image, HSOBEL_WEIGHTS))
  File     "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/scipy/ndimage/filt    ers.py", line 664, in convolve
    origin, True)
  File     "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/scipy/ndimage/filt    ers.py", line 498, in _correlate_or_convolve
    raise RuntimeError('filter weights array has incorrect shape.')
RuntimeError: filter weights array has incorrect shape.

如何将图像转换为类似于data.coins()中的数组

EN

回答 1

Stack Overflow用户

发布于 2014-09-22 06:52:25

你为什么不使用scikit-image的图片阅读器呢?否则,只需使用黑白版本来运行算法。为此,只需将参数'as_grey‘传递给imread (我正在使用scikit image):

代码语言:javascript
复制
image = skimage.io.imread(image_path,as_grey=True)

此参考可能会对您有所帮助:

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

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

https://stackoverflow.com/questions/25495219

复制
相关文章

相似问题

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