當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。