我正在尝试使用 Scipy 指南进行图像分析并搞乱一些事情,但是当我更改图像时,很多都不起作用。例如,
import skdemo
from skimage import data
# Rename module so we don't shadow the builtin function
import skimage.filter as filters
image = data.camera()
pixelated = image[::10, ::10]
gradient = filters.sobel(pixelated)
skdemo.imshow_all(pixelated, gradient)
当我运行它时,它可以工作,但是当我使用时,data.coffee()
或者data.chelsea()
我得到了大量的错误。每当我使用该convolve
功能时,也会发生这种情况。知道为什么吗?
RuntimeError Traceback (most recent call last)
<ipython-input-148-2dc2336cd0ef> in <module>()
6 image = data.coffee()
7 pixelated = image[::10, ::10]
----> 8 gradient = filters.sobel(pixelated)
9 skdemo.imshow_all(pixelated, gradient)
/Users/(me)/anaconda/lib/python2.7/site-packages/skimage/filter/edges.pyc in sobel(image, mask)
81 has to be further processed to perform edge detection.
82 """
---> 83 return np.sqrt(hsobel(image, mask)**2 + vsobel(image, mask)**2)
84
85
/Users/(me)/anaconda/lib/python2.7/site-packages/skimage/filter/edges.pyc in hsobel(image, mask)
112 """
113 image = img_as_float(image)
--> 114 result = np.abs(convolve(image, HSOBEL_WEIGHTS))
115 return _mask_filter_result(result, mask)
116
/Users/(me)/anaconda/lib/python2.7/site-packages/scipy/ndimage/filters.pyc in convolve(input, weights, output, mode, cval, origin)
693 """
694 return _correlate_or_convolve(input, weights, output, mode, cval,
--> 695 origin, True)
696
697
/Users/(me)/anaconda/lib/python2.7/site-packages/scipy/ndimage/filters.pyc in _correlate_or_convolve(input, weights, output, mode, cval, origin, convolution)
527 wshape = [ii for ii in weights.shape if ii > 0]
528 if len(wshape) != input.ndim:
--> 529 raise RuntimeError('filter weights array has incorrect shape.')
530 if convolution:
531 weights = weights[tuple([slice(None, None, -1)] * weights.ndim)]
RuntimeError: filter weights array has incorrect shape.