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


Python ndimage.correlate方法代码示例

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


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

示例1: test_correlate03

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import correlate [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

示例2: test_correlate01

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import correlate [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

示例3: test_correlate13

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import correlate [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

示例4: test_correlate14

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import correlate [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

示例5: test_correlate19

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import correlate [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

示例6: test_generic_filter01

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import correlate [as 别名]
def test_generic_filter01(self):
        filter_ = numpy.array([[1.0, 2.0], [3.0, 4.0]])
        footprint = numpy.array([[1, 0], [0, 1]])
        cf = numpy.array([1., 4.])

        def _filter_func(buffer, weights, total=1.0):
            weights = cf / total
            return (buffer * weights).sum()
        for type in self.types:
            a = numpy.arange(12, dtype=type)
            a.shape = (3,4)
            r1 = ndimage.correlate(a, filter_ * footprint)
            if type in self.float_types:
                r1 /= 5
            else:
                r1 //= 5
            r2 = ndimage.generic_filter(a, _filter_func,
                            footprint=footprint, extra_arguments=(cf,),
                            extra_keywords={'total': cf.sum()})
            assert_array_almost_equal(r1, r2) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:22,代码来源:test_ndimage.py

示例7: test_generic_filter01

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import correlate [as 别名]
def test_generic_filter01(self):
        filter_ = numpy.array([[1.0, 2.0], [3.0, 4.0]])
        footprint = numpy.array([[1, 0], [0, 1]])
        cf = numpy.array([1., 4.])

        def _filter_func(buffer, weights, total=1.0):
            weights = cf / total
            return (buffer * weights).sum()
        for type_ in self.types:
            a = numpy.arange(12, dtype=type_)
            a.shape = (3, 4)
            r1 = ndimage.correlate(a, filter_ * footprint)
            if type_ in self.float_types:
                r1 /= 5
            else:
                r1 //= 5
            r2 = ndimage.generic_filter(
                a, _filter_func, footprint=footprint, extra_arguments=(cf,),
                extra_keywords={'total': cf.sum()})
            assert_array_almost_equal(r1, r2) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:22,代码来源:test_ndimage.py

示例8: gabor_feature_single_job

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import correlate [as 别名]
def gabor_feature_single_job(a, filters, fm_i, label, cluster_center_number, save_flag):
    # convolution
    start_time = time.time()
    # b=SN.correlate(a,filters[i]) # too slow
    b = signal.correlate(a, filters[fm_i], mode='same')
    end_time = time.time()
    print('feature %d done (%f s)' % (fm_i, end_time - start_time))

    # show Gabor filter output
    if save_flag:
        img = (b[:, :, int(a.shape[2] / 2)]).copy()
        plt.imsave('./result/gabor_output(%d).png' % fm_i, img, cmap='gray')  # save fig

    # generate feature vector
    start_time = time.time()
    result = generate_feature_vector(b=b, label=label, cluster_center_number=cluster_center_number)
    end_time = time.time()
    print('feature vector %d done (%f s)' % (fm_i, end_time - start_time))
    return fm_i, result 
开发者ID:xulabs,项目名称:aitom,代码行数:21,代码来源:saliency_detection.py

示例9: _scc_single

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import correlate [as 别名]
def _scc_single(GT,P,win,ws):
	def _scc_filter(inp, axis, output, mode, cval):
		return correlate(inp, win , output, mode, cval, 0)

	GT_hp = generic_laplace(GT.astype(np.float64), _scc_filter)
	P_hp = generic_laplace(P.astype(np.float64), _scc_filter)
	win = fspecial(Filter.UNIFORM,ws)
	sigmaGT_sq,sigmaP_sq,sigmaGT_P = _get_sigmas(GT_hp,P_hp,win)

	sigmaGT_sq[sigmaGT_sq<0] = 0
	sigmaP_sq[sigmaP_sq<0] = 0

	den = np.sqrt(sigmaGT_sq) * np.sqrt(sigmaP_sq)
	idx = (den==0)
	den = _replace_value(den,0,1)
	scc = sigmaGT_P / den
	scc[idx] = 0
	return scc 
开发者ID:andrewekhalel,项目名称:sewar,代码行数:20,代码来源:full_ref.py

示例10: test_reference_correlation

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import correlate [as 别名]
def test_reference_correlation():
    ndim = 4
    shape = np.random.randint(2, 20, size=ndim)
    x = np.random.random(shape)
    kern = reduce(np.outer, [[-1, 0, 0, 1]] * ndim).reshape((4,) * ndim)
    px = np.pad(x, (2, 1), mode='reflect')
    pxi = integral_image(px)
    mean_fast = th.correlate_sparse(pxi, kern / 3 ** ndim, mode='valid')
    mean_ref = ndi.correlate(x, np.ones((3,) * ndim) / 3 ** ndim,
                             mode='mirror')
    np.testing.assert_allclose(mean_fast, mean_ref) 
开发者ID:jni,项目名称:skan,代码行数:13,代码来源:test_vendored_correlate.py

示例11: test_correlate02

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import correlate [as 别名]
def test_correlate02(self):
        array = numpy.array([1, 2, 3])
        kernel = numpy.array([1])

        output = ndimage.correlate(array, kernel)
        assert_array_almost_equal(array, output)

        output = ndimage.convolve(array, kernel)
        assert_array_almost_equal(array, output)

        output = ndimage.correlate1d(array, kernel)
        assert_array_almost_equal(array, output)

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

示例12: test_correlate04

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import correlate [as 别名]
def test_correlate04(self):
        array = numpy.array([1, 2])
        tcor = [2, 3]
        tcov = [3, 4]
        weights = numpy.array([1, 1])
        output = ndimage.correlate(array, weights)
        assert_array_almost_equal(output, tcor)
        output = ndimage.convolve(array, weights)
        assert_array_almost_equal(output, tcov)
        output = ndimage.correlate1d(array, weights)
        assert_array_almost_equal(output, tcor)
        output = ndimage.convolve1d(array, weights)
        assert_array_almost_equal(output, tcov) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:15,代码来源:test_ndimage.py

示例13: test_correlate05

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import correlate [as 别名]
def test_correlate05(self):
        array = numpy.array([1, 2, 3])
        tcor = [2, 3, 5]
        tcov = [3, 5, 6]
        kernel = numpy.array([1, 1])
        output = ndimage.correlate(array, kernel)
        assert_array_almost_equal(tcor, output)
        output = ndimage.convolve(array, kernel)
        assert_array_almost_equal(tcov, output)
        output = ndimage.correlate1d(array, kernel)
        assert_array_almost_equal(tcor, output)
        output = ndimage.convolve1d(array, kernel)
        assert_array_almost_equal(tcov, output) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:15,代码来源:test_ndimage.py

示例14: test_correlate07

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import correlate [as 别名]
def test_correlate07(self):
        array = numpy.array([1, 2, 3])
        expected = [5, 8, 11]
        weights = numpy.array([1, 2, 1])
        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,代码行数:14,代码来源:test_ndimage.py

示例15: test_correlate08

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import correlate [as 别名]
def test_correlate08(self):
        array = numpy.array([1, 2, 3])
        tcor = [1, 2, 5]
        tcov = [3, 6, 7]
        weights = numpy.array([1, 2, -1])
        output = ndimage.correlate(array, weights)
        assert_array_almost_equal(output, tcor)
        output = ndimage.convolve(array, weights)
        assert_array_almost_equal(output, tcov)
        output = ndimage.correlate1d(array, weights)
        assert_array_almost_equal(output, tcor)
        output = ndimage.convolve1d(array, weights)
        assert_array_almost_equal(output, tcov) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:15,代码来源:test_ndimage.py


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