當前位置: 首頁>>代碼示例>>Python>>正文


Python filters.convolve方法代碼示例

本文整理匯總了Python中scipy.ndimage.filters.convolve方法的典型用法代碼示例。如果您正苦於以下問題:Python filters.convolve方法的具體用法?Python filters.convolve怎麽用?Python filters.convolve使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在scipy.ndimage.filters的用法示例。


在下文中一共展示了filters.convolve方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: create_harmonic_mask

# 需要導入模塊: from scipy.ndimage import filters [as 別名]
# 或者: from scipy.ndimage.filters import convolve [as 別名]
def create_harmonic_mask(self, melody_signal):
        """
        Creates a harmonic mask from the melody signal. The mask is smoothed to reduce 
        the effects of discontinuities in the melody synthesizer.
        """
        stft = np.abs(melody_signal.stft())

        # Need to threshold the melody stft since the synthesized
        # F0 sequence overtones are at different weights.
        stft = stft ** self.compression
        stft /= np.maximum(np.max(stft, axis=1, keepdims=True), 1e-7)

        mask = np.empty(self.stft.shape)

        # Smoothing the mask row-wise using a low-pass filter to
        # get rid of discontuinities in the mask.
        kernel = np.full((1, self.smooth_length), 1 / self.smooth_length)
        for ch in range(self.audio_signal.num_channels):
            mask[..., ch] = convolve(stft[..., ch], kernel)
        return mask 
開發者ID:nussl,項目名稱:nussl,代碼行數:22,代碼來源:melodia.py

示例2: getEnergy

# 需要導入模塊: from scipy.ndimage import filters [as 別名]
# 或者: from scipy.ndimage.filters import convolve [as 別名]
def getEnergy(image):
	
	filter_x = np.array([
		[1.0, 2.0, 1.0],
		[0.0, 0.0, 0.0],
		[-1.0, -2.0, -1.0],
		])

	filter_x = np.stack([filter_x] * 3, axis = 2)

	filter_y = np.array([
		[1.0, 0.0, -1.0],
		[2.0, 0.0, -2.0],
		[1.0, 0.0, -1.0],
		])

	filter_y = np.stack([filter_y] * 3, axis = 2)

	image = image.astype('float32')

	convoluted = np.absolute(convolve(image, filter_x)) + np.absolute(convolve(image, filter_y))

	energy_map = convoluted.sum(axis = 2)

	return energy_map 
開發者ID:avidLearnerInProgress,項目名稱:pyCAIR,代碼行數:27,代碼來源:seam_carve.py

示例3: _convolve_rand

# 需要導入模塊: from scipy.ndimage import filters [as 別名]
# 或者: from scipy.ndimage.filters import convolve [as 別名]
def _convolve_rand(dshape, hshape, assert_close = True, test_subblocks = True):
    print("convolving test: dshape = %s, hshape  = %s" % (dshape, hshape))
    np.random.seed(1)
    d = np.random.uniform(-1, 1, dshape).astype(np.float32)
    h = np.random.uniform(-1, 1, hshape).astype(np.float32)


    print("gputools")
    outs = [gputools.convolve(d, h)]

    print("scipy")
    out1 = sp_filter.convolve(d, h, mode="constant", cval = 0.)

    if test_subblocks:
        outs.append(gputools.convolve(d, h, sub_blocks=(2, 3, 4)))

    if assert_close:
        for out in outs:
            npt.assert_allclose(out1, out, rtol=1.e-2, atol=1.e-3)

    return [out1]+outs 
開發者ID:maweigert,項目名稱:gputools,代碼行數:23,代碼來源:test_convolve.py

示例4: calculate_sift_grid

# 需要導入模塊: from scipy.ndimage import filters [as 別名]
# 或者: from scipy.ndimage.filters import convolve [as 別名]
def calculate_sift_grid(self, image, rangeH, rangeW):
        H, W = image.shape
        feat = np.zeros((len(rangeH), len(rangeW), self.Nsamples*self.Nangles))
        IH = filters.convolve(image, self.GH, mode='nearest')
        IW = filters.convolve(image, self.GW, mode='nearest')
        I_mag = np.sqrt(IH ** 2 + IW ** 2)
        I_theta = np.arctan2(IH, IW)
        I_orient = np.empty((H, W, self.Nangles))
        for i in range(self.Nangles):
            I_orient[:,:,i] = I_mag * np.maximum(
                    np.cos(I_theta - self.angles[i]) ** self.alpha, 0)
        for i, hs in enumerate(rangeH):
            for j, ws in enumerate(rangeW):
                feat[i, j] = np.dot(self.weights,
                                    I_orient[hs:hs+self.pS, ws:ws+self.pS]\
                                        .reshape(self.pS**2, self.Nangles)
                                   ).flat
        return feat 
開發者ID:douwekiela,項目名稱:mmfeat,代碼行數:20,代碼來源:dsift.py

示例5: get_mask_from_prob

# 需要導入模塊: from scipy.ndimage import filters [as 別名]
# 或者: from scipy.ndimage.filters import convolve [as 別名]
def get_mask_from_prob(self, cloud_probs, threshold=None):
        """
        Returns cloud mask by applying morphological operations -- convolution and dilation --
        to input cloud probabilities.

        :param cloud_probs: cloud probability map
        :type cloud_probs: numpy array of cloud probabilities (shape n_images x n x m)
        :param threshold: A float from [0,1] specifying threshold
        :type threshold: float
        :return: raster cloud mask
        :rtype: numpy array (shape n_images x n x m)
        """
        threshold = self.threshold if threshold is None else threshold

        if self.average_over:
            cloud_masks = np.asarray([convolve(cloud_prob, self.conv_filter) > threshold
                                      for cloud_prob in cloud_probs], dtype=np.int8)
        else:
            cloud_masks = (cloud_probs > threshold).astype(np.int8)

        if self.dilation_size:
            cloud_masks = np.asarray([dilation(cloud_mask, self.dilation_filter) for cloud_mask in cloud_masks],
                                     dtype=np.int8)
        return cloud_masks 
開發者ID:sentinel-hub,項目名稱:sentinel2-cloud-detector,代碼行數:26,代碼來源:S2PixelCloudDetector.py

示例6: oral_cavity_filt

# 需要導入模塊: from scipy.ndimage import filters [as 別名]
# 或者: from scipy.ndimage.filters import convolve [as 別名]
def oral_cavity_filt(pole_amps, pole_freqs,fs):
    """
    This model for generating singing vowel sounds from sine tones comes
    from:

    https://simonl02.users.greyc.fr/files/Documents/Teaching/SignalProcessingLabs/lab3.pdf

    The above will be referred to throughout these docstrings as THE DOCUMENT.

    Original author: Fatemeh Pishdadian

    The arguments to the fucntions throughout this text follow the 
    signatures laid out in THE DOCUMENT.

    This is used in Melodia to generate the melody signal to produce a 
    mask.

    Solves "Q. Write a function to synthesize filter H(z)" in 
    THE DOCUMENT
    """
    num_pole_pair = len(pole_amps)
    poles = pole_amps * np.exp(1j * 2 * np.pi * pole_freqs / fs)
    poles_conj = np.conj(poles)

    denom_coeffs = 1
    for i in range(num_pole_pair):
        pole_temp = poles[i]
        pole_conj_temp = poles_conj[i]
        pole_pair_coeffs = np.convolve(np.array([1,-pole_temp]),np.array([1,-pole_conj_temp]))

        denom_coeffs = np.convolve(denom_coeffs, pole_pair_coeffs)
    return denom_coeffs 
開發者ID:nussl,項目名稱:nussl,代碼行數:34,代碼來源:melodia.py

示例7: conv

# 需要導入模塊: from scipy.ndimage import filters [as 別名]
# 或者: from scipy.ndimage.filters import convolve [as 別名]
def conv(input, weights):
    return convolve(input, weights) 
開發者ID:Alfredvc,項目名稱:cnn_workshop,代碼行數:4,代碼來源:util.py

示例8: test_reflect

# 需要導入模塊: from scipy.ndimage import filters [as 別名]
# 或者: from scipy.ndimage.filters import convolve [as 別名]
def test_reflect():
    image = np.ones((5, 5))
    image[2, 2] = 0
    h = np.array([[-1, -2, -1], [0, 0, 0], [1, 2, 1]])
    out = gputools.convolve(image, h, mode='reflect')
    npt.assert_allclose(out[0], [0,] * 5)
    npt.assert_allclose(out[1], [0, 1, 2, 1, 0]) 
開發者ID:maweigert,項目名稱:gputools,代碼行數:9,代碼來源:test_convolve.py

示例9: _conv_sep2_numpy

# 需要導入模塊: from scipy.ndimage import filters [as 別名]
# 或者: from scipy.ndimage.filters import convolve [as 別名]
def _conv_sep2_numpy(d, hx, hy):
    tmp = sp_filter.convolve(d, hx.reshape((1, len(hx))), mode="constant")
    return sp_filter.convolve(tmp, hy.reshape((len(hy), 1)), mode="constant") 
開發者ID:maweigert,項目名稱:gputools,代碼行數:5,代碼來源:test_convolve_sep.py

示例10: _conv_sep3_numpy

# 需要導入模塊: from scipy.ndimage import filters [as 別名]
# 或者: from scipy.ndimage.filters import convolve [as 別名]
def _conv_sep3_numpy(d, hx, hy, hz):
    res = sp_filter.convolve(d, hx.reshape((1, 1, len(hx))), mode="constant")
    tmp = sp_filter.convolve(res, hy.reshape((1, len(hy), 1)), mode="constant")
    return sp_filter.convolve(tmp, hz.reshape((len(hz), 1, 1)), mode="constant") 
開發者ID:maweigert,項目名稱:gputools,代碼行數:6,代碼來源:test_convolve_sep.py

示例11: computeDerivatives

# 需要導入模塊: from scipy.ndimage import filters [as 別名]
# 或者: from scipy.ndimage.filters import convolve [as 別名]
def computeDerivatives(im1: np.ndarray, im2: np.ndarray) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:

    fx = filter2(im1, kernelX) + filter2(im2, kernelX)
    fy = filter2(im1, kernelY) + filter2(im2, kernelY)

    # ft = im2 - im1
    ft = filter2(im1, kernelT) + filter2(im2, -kernelT)

    return fx, fy, ft 
開發者ID:scivision,項目名稱:pyoptflow,代碼行數:11,代碼來源:hornschunck.py

示例12: predict

# 需要導入模塊: from scipy.ndimage import filters [as 別名]
# 或者: from scipy.ndimage.filters import convolve [as 別名]
def predict(pdf, offset, kernel, mode='wrap', cval=0.):
    """ Performs the discrete Bayes filter prediction step, generating
    the prior.

    `pdf` is a discrete probability distribution expressing our initial
    belief.

    `offset` is an integer specifying how much we want to move to the right
    (negative values means move to the left)

    We assume there is some noise in that offset, which we express in `kernel`.
    For example, if offset=3 and kernel=[.1, .7., .2], that means we think
    there is a 70% chance of moving right by 3, a 10% chance of moving 2
    spaces, and a 20% chance of moving by 4.

    It returns the resulting distribution.

    If `mode='wrap'`, then the probability distribution is wrapped around
    the array.

    If `mode='constant'`, or any other value the pdf is shifted, with `cval`
    used to fill in missing elements.

    Examples
    --------
    .. code-block:: Python

        belief = [.05, .05, .05, .05, .55, .05, .05, .05, .05, .05]
        prior = predict(belief, offset=2, kernel=[.1, .8, .1])
    """

    if mode == 'wrap':
        return convolve(np.roll(pdf, offset), kernel, mode='wrap')

    return convolve(shift(pdf, offset, cval=cval), kernel,
                    cval=cval, mode='constant') 
開發者ID:rlabbe,項目名稱:filterpy,代碼行數:38,代碼來源:discrete_bayes.py

示例13: ssim

# 需要導入模塊: from scipy.ndimage import filters [as 別名]
# 或者: from scipy.ndimage.filters import convolve [as 別名]
def ssim(img1, img2, cs_map=False):
    """Return the Structural Similarity Map corresponding to input images img1
    and img2 (images are assumed to be uint8)

    This function attempts to mimic precisely the functionality of ssim.m a
    MATLAB provided by the author's of SSIM
    https://ece.uwaterloo.ca/~z70wang/research/ssim/ssim_index.m
    """
    # img1 = img1.astype('float32')
    # img2 = img2.astype('float32')

    K1 = 0.01
    K2 = 0.03
    L = 255
    C1 = (K1 * L) ** 2
    C2 = (K2 * L) ** 2

    mu1 = convolve(window, img1, mode='nearest')
    mu2 = convolve(window, img2, mode='nearest')
    mu1_sq = mu1 * mu1
    mu2_sq = mu2 * mu2
    mu1_mu2 = mu1 * mu2
    sigma1_sq = convolve(window, img1 * img1, mode='nearest') - mu1_sq
    sigma2_sq = convolve(window, img2 * img2, mode='nearest') - mu2_sq
    sigma12 = convolve(window, img1 * img2, mode='nearest') - mu1_mu2

    if cs_map:
        return (((2 * mu1_mu2 + C1) * (2 * sigma12 + C2)) /
                ((mu1_sq + mu2_sq + C1) * (sigma1_sq + sigma2_sq + C2)),
                (2.0 * sigma12 + C2) / (sigma1_sq + sigma2_sq + C2))
    else:
        return (((2 * mu1_mu2 + C1) * (2 * sigma12 + C2)) /
                ((mu1_sq + mu2_sq + C1) * (sigma1_sq + sigma2_sq + C2))) 
開發者ID:jongyookim,項目名稱:IQA_BIECON_release,代碼行數:35,代碼來源:ssim.py

示例14: local_normalize_1ch

# 需要導入模塊: from scipy.ndimage import filters [as 別名]
# 或者: from scipy.ndimage.filters import convolve [as 別名]
def local_normalize_1ch(img, const=127.0):
    mu = convolve(img, kern, mode='nearest')
    mu_sq = mu * mu
    im_sq = img * img
    tmp = convolve(im_sq, kern, mode='nearest') - mu_sq
    sigma = np.sqrt(np.abs(tmp))
    structdis = (img - mu) / (sigma + const)

    # Rescale within 0 and 1
    # structdis = (structdis + 3) / 6
    structdis = 2. * structdis / 3.
    return structdis 
開發者ID:jongyookim,項目名稱:IQA_BIECON_release,代碼行數:14,代碼來源:data_loader_IQA.py

示例15: local_normalize

# 需要導入模塊: from scipy.ndimage import filters [as 別名]
# 或者: from scipy.ndimage.filters import convolve [as 別名]
def local_normalize(img, num_ch=1, const=127.0):
    if num_ch == 1:
        mu = convolve(img[:, :, 0], kern, mode='nearest')
        mu_sq = mu * mu
        im_sq = img[:, :, 0] * img[:, :, 0]
        tmp = convolve(im_sq, kern, mode='nearest') - mu_sq
        sigma = np.sqrt(np.abs(tmp))
        structdis = (img[:, :, 0] - mu) / (sigma + const)

        # Rescale within 0 and 1
        # structdis = (structdis + 3) / 6
        structdis = 2. * structdis / 3.
        norm = structdis[:, :, None]
    elif num_ch > 1:
        norm = np.zeros(img.shape, dtype='float32')
        for ch in range(num_ch):
            mu = convolve(img[:, :, ch], kern, mode='nearest')
            mu_sq = mu * mu
            im_sq = img[:, :, ch] * img[:, :, ch]
            tmp = convolve(im_sq, kern, mode='nearest') - mu_sq
            sigma = np.sqrt(np.abs(tmp))
            structdis = (img[:, :, ch] - mu) / (sigma + const)

            # Rescale within 0 and 1
            # structdis = (structdis + 3) / 6
            structdis = 2. * structdis / 3.
            norm[:, :, ch] = structdis

    return norm 
開發者ID:jongyookim,項目名稱:IQA_BIECON_release,代碼行數:31,代碼來源:data_loader_IQA.py


注:本文中的scipy.ndimage.filters.convolve方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。