2014-09-30 112 views
0

我正在嘗試使用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. 
+0

您可以發佈錯誤 – ragingSloth 2014-09-30 03:02:45

回答

2

sobel需要一個二維數組。由skimage.data.coffee()skimage.data.chelsea()返回的數組是三維的,具有形狀(m,n,3)。它們代表彩色圖像,具有紅色,綠色和藍色通道。

要將其中的一個與演示代碼一起使用,您可以選擇其中一個通道。例如,以下工作:

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