2

エラーメッセージ:

operands could not be broadcast together with shapes (603) (613)

私は何をすべきか?
リストは両方とも同じ長さである必要がありますか?
または、ゼロパッドする必要がありますか?

これが私のコードです:

def gaussian_smooth1(img, sigma): 
    '''
    Do gaussian smoothing with sigma.
    Returns the smoothed image.
    '''
    result = np.zeros_like(img)

    #get the filter
    filter = gaussian_filter(sigma)

    #get the height and width of img
    width = len(img[0])
    height = len(img)

    #smooth every color-channel
    for c in range(3):
        #smooth the 2D image img[:,:,c]
        #tip: make use of numpy.convolve
        for x in range(height):
            result[x,:,c] = np.convolve(filter,img[x,:,c])
        for y in range(width):
            result[:,y,c] = np.convolve(filter,img[:,y,c])
    return result
4

1 に答える 1

1

権利を指定しないために問題が発生しますmode
ドキュメントでそれを読んでください:
numpy.convolve

numpy.convolveのデフォルトはですmode='full'

これにより、(N + M-1)の出力形状で、オーバーラップの各ポイントで畳み込みが返されます。

Nは入力配列Mのサイズ、はフィルターのサイズです。したがって、出力は入力よりも大きくなります。

代わりにを使用しますnp.convolve(filter,img[...],mode='same')

FFTを使用した2D畳み込みを可能にする scipy.convolveもご覧ください。

于 2013-02-20T01:12:11.437 に答える