当前位置: 首页>>代码示例>>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;未经允许,请勿转载。