Python 渐变适用于一张照片,但不适用于其他照片

Python 渐变适用于一张照片,但不适用于其他照片,python,scipy,scikit-image,Python,Scipy,Scikit Image,我试着用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.

我试着用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()
时,我会遇到大量错误。每当我使用
convalve
函数时,也会发生这种情况。知道为什么吗

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.
运行时错误回溯(最近一次调用)
在()
6 image=data.coffee()
7像素化=图像[::10,::10]
---->8渐变=过滤器。sobel(像素化)
9 skdemo.imshow_all(像素化、渐变)
/sobel中的用户/(me)/anaconda/lib/python2.7/site-packages/skimage/filter/edges.pyc(图像,掩码)
81必须进一步处理以执行边缘检测。
82     """
--->83返回np.sqrt(hsobel(图像,遮罩)**2+vsobel(图像,遮罩)**2)
84
85
/hsobel中的Users/(me)/anaconda/lib/python2.7/site-packages/skimage/filter/edges.pyc(图像,掩码)
112     """
113图像=img_as_float(图像)
-->114结果=np.abs(卷积(图像,HSOBEL_权重))
115返回_掩码_过滤器_结果(结果,掩码)
116
/卷积中的用户/(me)/anaconda/lib/python2.7/site-packages/scipy/ndimage/filters.pyc(输入、权重、输出、模式、cval、原点)
693     """
694返回相关或卷积(输入、权重、输出、模式、cval、,
-->695(真实来源)
696
697
/用户/(me)/anaconda/lib/python2.7/site-packages/scipy/ndimage/filters.pyc在相关或卷积(输入、权重、输出、模式、cval、原点、卷积)中
527 wshape=[ii代表ii的重量。ii>0时的形状]
528如果len(wshape)!=input.ndim:
-->529 raise RUNTIMERROR('过滤器权重数组的形状不正确')
530如果卷积:
531权重=权重[元组([切片(无,无,-1)]*weights.ndim]
运行时错误:筛选器权重数组的形状不正确。

sobel
需要一个二维数组。
skipage.data.coffee()
skipage.data.chelsea()
返回的数组是三维的,有形状(m,n,3)。它们代表彩色图像,有红色、绿色和蓝色通道

要在演示代码中使用其中一个频道,您可以选择其中一个频道。例如,以下功能:

image = data.coffee()
pixelated = image[::10, ::10, 0]  # Use the red channel.
gradient = filters.sobel(pixelated)

你能把错误贴出来吗