尝试使用Python语言中的filter.sobel()函数。
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:
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()中的数组
发布于 2014-09-22 06:52:25
你为什么不使用scikit-image的图片阅读器呢?否则,只需使用黑白版本来运行算法。为此,只需将参数'as_grey‘传递给imread (我正在使用scikit image):
image = skimage.io.imread(image_path,as_grey=True)此参考可能会对您有所帮助:
http://scikit-image.org/docs/dev/api/skimage.io.html#imread
https://stackoverflow.com/questions/25495219
复制相似问题