当前位置: 首页>>代码示例>>Python>>正文


Python ndimage.convolve方法代码示例

本文整理汇总了Python中scipy.ndimage.convolve方法的典型用法代码示例。如果您正苦于以下问题:Python ndimage.convolve方法的具体用法?Python ndimage.convolve怎么用?Python ndimage.convolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy.ndimage的用法示例。


在下文中一共展示了ndimage.convolve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: pyconv3d

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import convolve [as 别名]
def pyconv3d(signals, filters):
    Ns, Ts, C, Hs, Ws = signals.shape
    Nf, Tf, C, Hf, Wf = filters.shape

    Tf2 = Tf//2
    Hf2 = Hf//2
    Wf2 = Wf//2

    rval = numpy.zeros((Ns, Ts-Tf+1, Nf, Hs-Hf+1, Ws-Wf+1))
    for ns in xrange(Ns):
        for nf in xrange(Nf):
            for c in xrange(C):
                s_i = signals[ns, :, c, :, :]
                f_i = filters[nf, :, c, :, :]
                r_i = rval[ns, :, nf, :, :]
                o_i = ndimage.convolve(s_i, f_i, mode='constant', cval=1)
                o_i_sh0 = o_i.shape[0]
                # print s_i.shape, f_i.shape, r_i.shape, o_i.shape
                r_i += o_i[Tf2:o_i_sh0-Tf2, Hf2:-Hf2, Wf2:-Wf2]
    return rval 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:22,代码来源:test_conv3d2d.py

示例2: high_pass_filter

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import convolve [as 别名]
def high_pass_filter(input_image, output_image): 

    I = imread(input_image)
    if len(I.shape)==3:
        kernel = np.array([[[-1, -1, -1],
                            [-1,  8, -1],
                            [-1, -1, -1]],
                           [[-1, -1, -1],
                            [-1,  8, -1],
                            [-1, -1, -1]],
                           [[-1, -1, -1],
                            [-1,  8, -1],
                            [-1, -1, -1]]])
    else:
        kernel = np.array([[-1, -1, -1],
                           [-1,  8, -1],
                           [-1, -1, -1]])


    If = ndimage.convolve(I, kernel)
    imsave(output_image, If)
# }}}

# {{{ low_pass_filter() 
开发者ID:daniellerch,项目名称:aletheia,代码行数:26,代码来源:attacks.py

示例3: test_correlate01

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import convolve [as 别名]
def test_correlate01(self):
        array = numpy.array([1, 2])
        weights = numpy.array([2])
        expected = [2, 4]

        output = ndimage.correlate(array, weights)
        assert_array_almost_equal(output, expected)

        output = ndimage.convolve(array, weights)
        assert_array_almost_equal(output, expected)

        output = ndimage.correlate1d(array, weights)
        assert_array_almost_equal(output, expected)

        output = ndimage.convolve1d(array, weights)
        assert_array_almost_equal(output, expected) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:18,代码来源:test_ndimage.py

示例4: test_correlate03

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import convolve [as 别名]
def test_correlate03(self):
        array = numpy.array([1])
        weights = numpy.array([1, 1])
        expected = [2]

        output = ndimage.correlate(array, weights)
        assert_array_almost_equal(output, expected)

        output = ndimage.convolve(array, weights)
        assert_array_almost_equal(output, expected)

        output = ndimage.correlate1d(array, weights)
        assert_array_almost_equal(output, expected)

        output = ndimage.convolve1d(array, weights)
        assert_array_almost_equal(output, expected) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:18,代码来源:test_ndimage.py

示例5: test_correlate13

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import convolve [as 别名]
def test_correlate13(self):
        kernel = numpy.array([[1, 0],
                              [0, 1]])
        for type1 in self.types:
            array = numpy.array([[1, 2, 3],
                                 [4, 5, 6]], type1)
            for type2 in self.types:
                output = ndimage.correlate(array, kernel,
                                                    output=type2)
                assert_array_almost_equal([[2, 3, 5], [5, 6, 8]], output)
                assert_equal(output.dtype.type, type2)

                output = ndimage.convolve(array, kernel,
                                          output=type2)
                assert_array_almost_equal([[6, 8, 9], [9, 11, 12]], output)
                assert_equal(output.dtype.type, type2) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:18,代码来源:test_ndimage.py

示例6: test_correlate14

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import convolve [as 别名]
def test_correlate14(self):
        kernel = numpy.array([[1, 0],
                              [0, 1]])
        for type1 in self.types:
            array = numpy.array([[1, 2, 3],
                                 [4, 5, 6]], type1)
            for type2 in self.types:
                output = numpy.zeros(array.shape, type2)
                ndimage.correlate(array, kernel,
                                  output=output)
                assert_array_almost_equal([[2, 3, 5], [5, 6, 8]], output)
                assert_equal(output.dtype.type, type2)

                ndimage.convolve(array, kernel, output=output)
                assert_array_almost_equal([[6, 8, 9], [9, 11, 12]], output)
                assert_equal(output.dtype.type, type2) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:18,代码来源:test_ndimage.py

示例7: test_correlate19

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import convolve [as 别名]
def test_correlate19(self):
        kernel = numpy.array([[1, 0],
                              [0, 1]])
        for type1 in self.types:
            array = numpy.array([[1, 2, 3],
                                 [4, 5, 6]], type1)
            output = ndimage.correlate(array, kernel,
                                       output=numpy.float32,
                                       mode='nearest', origin=[-1, 0])
            assert_array_almost_equal([[5, 6, 8], [8, 9, 11]], output)
            assert_equal(output.dtype.type, numpy.float32)

            output = ndimage.convolve(array, kernel,
                                      output=numpy.float32,
                                      mode='nearest', origin=[-1, 0])
            assert_array_almost_equal([[3, 5, 6], [6, 8, 9]], output)
            assert_equal(output.dtype.type, numpy.float32) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:19,代码来源:test_ndimage.py

示例8: low_pass_filter

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import convolve [as 别名]
def low_pass_filter(input_image, output_image): 

    I = imread(input_image)
    if len(I.shape)==3:
        kernel = np.array([[[1, 1, 1],
                            [1, 1, 1],
                            [1, 1, 1]],
                           [[1, 1, 1],
                            [1, 1, 1],
                            [1, 1, 1]],
                           [[1, 1, 1],
                            [1, 1, 1],
                            [1, 1, 1]]])
    else:
        kernel = np.array([[1, 1, 1],
                           [1, 1, 1],
                           [1, 1, 1]])

    kernel = kernel.astype('float32')/9
    If = ndimage.convolve(I, kernel)
    imsave(output_image, If)
# }}}

# {{{ imgdiff() 
开发者ID:daniellerch,项目名称:aletheia,代码行数:26,代码来源:attacks.py

示例9: get_ini_cor

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import convolve [as 别名]
def get_ini_cor(cor_img, d1=21, d2=3):
    cor = convolve(cor_img, np.ones((d1, d1)), mode='constant', cval=0.0)
    cor_id = []
    X_loc = find_N_peaks(cor.sum(0), prominence=None,
                         distance=20, N=4)[0]
    for x in X_loc:
        x_ = int(np.round(x))

        V_signal = cor[:, max(0, x_-d2):x_+d2+1].sum(1)
        y1, y2 = find_N_peaks(V_signal, prominence=None,
                              distance=20, N=2)[0]
        cor_id.append((x, y1))
        cor_id.append((x, y2))

    cor_id = np.array(cor_id, np.float64)

    return cor_id 
开发者ID:zouchuhang,项目名称:LayoutNetv2,代码行数:19,代码来源:pano_gen.py

示例10: circular_conv

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import convolve [as 别名]
def circular_conv(signal1, signal2):
    """takes two 1D numpy array and do a circular convolution with them
    inputs :
        - signal1 : 1D numpy array
        - signal2 : 1D numpy array, same length as signal1
    output :
        - signal_conv : 1D numpy array, result of circular convolution of signal1 and signal2"""

    if signal1.shape != signal2.shape:
        raise Exception("The two signals for circular convolution do not have the same shape")

    signal2_extended = np.concatenate((signal2, signal2, signal2))  # replicate signal at both ends

    signal_conv_extended = np.convolve(signal1, signal2_extended, mode="same")  # median filtering

    signal_conv = signal_conv_extended[len(signal1):2*len(signal1)]  # truncate back the signal

    return signal_conv 
开发者ID:neuropoly,项目名称:spinalcordtoolbox,代码行数:20,代码来源:msct_register.py

示例11: ApplyAtoms

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import convolve [as 别名]
def ApplyAtoms(V,D,scale):
    out=[]
    for s in xrange(scale):
        if s!=0:
            print('scale='+str(s))
            V = pyr.pyramid_reduce_3d(V,downscale=2) # reduce the volume. e.g. from 512^3 to 256^3
        else: print('scale=0')
        for i in xrange(len(D)):
            print('s:'+str(s)+' i:'+str(i))
            conv = nd.convolve(V, D[i], mode='constant', cval=0.0)
            if s==0:
                out.append(conv)
            else:
                upscaled = pyr.pyramid_expand_3d(conv, upscale=2**s)
                out.append(upscaled)
    out=np.array(out)
    return out 
开发者ID:konopczynski,项目名称:Vessel3DDL,代码行数:19,代码来源:UseClassifier.py

示例12: get_data

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import convolve [as 别名]
def get_data(self):

        image_iter = self.ds_images.get_data()
        psf_iter = self.ds_psf.get_data()

        for dp_image in image_iter:

            # sample camera shake kernel
            dp_psf = next(psf_iter)

            # synthesize ego-motion
            for t, k in enumerate(dp_psf):
                blurry = dp_image[t]
                for c in range(3):
                    blurry[:, :, c] = ndimage.convolve(blurry[:, :, c], k, mode='constant', cval=0.0)
                dp_image[t] = blurry

            yield dp_image 
开发者ID:cgtuebingen,项目名称:learning-blind-motion-deblurring,代码行数:20,代码来源:data_provider.py

示例13: compute_img_filter_response2d

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import convolve [as 别名]
def compute_img_filter_response2d(img, filter_battery):
    """ compute image filter response in 2D

    :param [[float]] img: image
    :param [[[float]]] filter_battery: filters
    :return [[float]]:
    """
    if filter_battery.ndim != 3:
        raise ValueError('wrong battery dim %r' % filter_battery.shape)
    responses = np.array([ndimage.convolve(img, fl) for fl in filter_battery])
    if filter_battery.shape[0] > 1:
        # usually for rotational edge detectors and we tae the maximal response
        response = np.max(responses, axis=0)
    else:
        response = responses[0]
    return response 
开发者ID:Borda,项目名称:pyImSegm,代码行数:18,代码来源:descriptors.py

示例14: convolve_mask

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import convolve [as 别名]
def convolve_mask(data, ksize=3, kernel=None, copy=True):
    """
    Convolve data over the missing regions of a mask

    Parameters
    ----------
    data : masked array_like
        Input field.
    ksize : int, optional
        Size of square kernel
    kernel : ndarray, optional
        Define a convolution kernel. Default is averaging
    copy : bool, optional
        If true, a copy of input array is made

    Returns
    -------
    fld : masked array
    """
    return convolve(data, ksize, kernel, copy, True) 
开发者ID:powellb,项目名称:seapy,代码行数:22,代码来源:lib.py

示例15: compute_gabor

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import convolve [as 别名]
def compute_gabor(img, params):
    if not params["shared_dict"].get("gabor_kernels", False):
        gabor_theta = int(params.get("gabor_theta", 4))
        gabor_sigma = make_tuple(params.get("gabor_sigma", "(1,3)"))
        gabor_frequency = make_tuple(params.get("gabor_frequency", "(0.05, 0.25)"))

        kernels = []
        for theta in range(gabor_theta):
            theta = theta / 4. * np.pi
            for sigma in gabor_sigma:
                for frequency in gabor_frequency:
                    kernel = np.real(gabor_kernel(frequency, theta=theta,
                                                  sigma_x=sigma, sigma_y=sigma))
                    kernels.append(kernel)
        params["shared_dict"]["gabor_kernels"] = kernels

    kernels = params["shared_dict"]["gabor_kernels"]
    imgg = rgb2gray(img)
    feats = np.zeros((imgg.shape[0], imgg.shape[1], len(kernels)), dtype=np.double)
    for k, kernel in enumerate(kernels):
        filtered = ndi.convolve(imgg, kernel, mode='wrap')
        feats[:, :, k] = filtered
    return feats 
开发者ID:choosehappy,项目名称:HistoQC,代码行数:25,代码来源:ClassificationModule.py


注:本文中的scipy.ndimage.convolve方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。