小编use*_*719的帖子

具有多维(或非标量)输出的Scipy滤波器

是否有类似于支持向量输出ndimagegeneric_filter的过滤器?我没有设法让scipy.ndimage.filters.generic_filter回报超过标量.取消注释下面代码中的行以获取错误:TypeError: only length-1 arrays can be converted to Python scalars.

我正在寻找一个处理2D或3D数组的通用过滤器,并在每个点返回一个向量.因此,输出将具有一个附加维度.对于下面的例子,我希望这样的事情:

m.shape    # (10,10)
res.shape  # (10,10,2)
Run Code Online (Sandbox Code Playgroud)

示例代码

import numpy as np
from scipy import ndimage

a = np.ones((10, 10)) * np.arange(10)

footprint = np.array([[1,1,1],
                    [1,0,1],
                    [1,1,1]])

def myfunc(x):
    r = sum(x)
    #r = np.array([1,1])  # uncomment this
    return r

res = ndimage.generic_filter(a, myfunc, footprint=footprint)
Run Code Online (Sandbox Code Playgroud)

python numpy image-processing scipy ndimage

6
推荐指数
1
解决办法
662
查看次数

标签 统计

image-processing ×1

ndimage ×1

numpy ×1

python ×1

scipy ×1