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


Python filters.median_filter方法代码示例

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


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

示例1: smooth_magseries_ndimage_medfilt

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import median_filter [as 别名]
def smooth_magseries_ndimage_medfilt(mags, windowsize):
    '''This smooths the magseries with a median filter that reflects the array
    at the boundary.

    See https://docs.scipy.org/doc/scipy/reference/tutorial/ndimage.html for
    details.

    Parameters
    ----------

    mags : np.array
        The input mags/flux time-series to smooth.

    windowsize : int
        This is a odd integer containing the smoothing window size.

    Returns
    -------

    np.array
        The smoothed mag/flux time-series array.

    '''
    return median_filter(mags, size=windowsize, mode='reflect') 
开发者ID:waqasbhatti,项目名称:astrobase,代码行数:26,代码来源:trends.py

示例2: pick_peaks

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import median_filter [as 别名]
def pick_peaks(nc, L=16, offset_denom=0.1):
    """Obtain peaks from a novelty curve using an adaptive threshold."""
    offset = nc.mean() * float(offset_denom)
    th = filters.median_filter(nc, size=L) + offset
    #th = filters.gaussian_filter(nc, sigma=L/2., mode="nearest") + offset
    #import pylab as plt
    #plt.plot(nc)
    #plt.plot(th)
    #plt.show()
    # th = np.ones(nc.shape[0]) * nc.mean() - 0.08
    peaks = []
    for i in range(1, nc.shape[0] - 1):
        # is it a peak?
        if nc[i - 1] < nc[i] and nc[i] > nc[i + 1]:
            # is it above the threshold?
            if nc[i] > th[i]:
                peaks.append(i)
    return peaks 
开发者ID:urinieto,项目名称:msaf,代码行数:20,代码来源:segmenter.py

示例3: pick_peaks

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import median_filter [as 别名]
def pick_peaks(nc, L=16):
    """Obtain peaks from a novelty curve using an adaptive threshold."""
    offset = nc.mean() / 20.

    nc = filters.gaussian_filter1d(nc, sigma=4)  # Smooth out nc

    th = filters.median_filter(nc, size=L) + offset
    #th = filters.gaussian_filter(nc, sigma=L/2., mode="nearest") + offset

    peaks = []
    for i in range(1, nc.shape[0] - 1):
        # is it a peak?
        if nc[i - 1] < nc[i] and nc[i] > nc[i + 1]:
            # is it above the threshold?
            if nc[i] > th[i]:
                peaks.append(i)
    #plt.plot(nc)
    #plt.plot(th)
    #for peak in peaks:
        #plt.axvline(peak)
    #plt.show()

    return peaks 
开发者ID:urinieto,项目名称:msaf,代码行数:25,代码来源:segmenter.py

示例4: filter_activation_matrix

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import median_filter [as 别名]
def filter_activation_matrix(G, R):
    """Filters the activation matrix G, and returns a flattened copy."""

    #import pylab as plt
    #plt.imshow(G, interpolation="nearest", aspect="auto")
    #plt.show()

    idx = np.argmax(G, axis=1)
    max_idx = np.arange(G.shape[0])
    max_idx = (max_idx, idx.flatten())
    G[:, :] = 0
    G[max_idx] = idx + 1

    # TODO: Order matters?
    G = np.sum(G, axis=1)
    G = median_filter(G[:, np.newaxis], R)

    return G.flatten() 
开发者ID:urinieto,项目名称:msaf,代码行数:20,代码来源:segmenter.py

示例5: set_prefilter

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import median_filter [as 别名]
def set_prefilter(self,gaussian = False, median = False, params = []):
        self._do_prefilter_data = False
        if gaussian or median:
            self._do_prefilter_data = True

        #print gaussian, median
        if median:
            self._prefilter = median_filter
            #print("median_filter")
            if params:
                self._prefilter_params = params[0]
            else:
                self._prefilter_params = 6

        if gaussian:
            self._prefilter = gaussian_filter1d
            #print("gaussian_filter1d")
            if params:
                self._prefilter_params = params[0]
            else:
                self._prefilter_params = 6 # 0.4 
开发者ID:qkitgroup,项目名称:qkit,代码行数:23,代码来源:resonator.py

示例6: _smooth_raster

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import median_filter [as 别名]
def _smooth_raster(self, raster, ws, resolution, circular=False):
        """ Smooth a raster with a median filter

        Parameters
        ----------
        raster :      ndarray
                      raster to be smoothed
        ws :          int
                      window size of smoothing filter
        resolution :  int
                      resolution of raster in m
        circular :    bool, optional
                      set to True for disc-shaped filter kernel, block otherwise

        Returns
        -------
        ndarray
            smoothed raster
        """
        return filters.median_filter(
            raster, footprint=self._get_kernel(ws, circular=circular)) 
开发者ID:manaakiwhenua,项目名称:pycrown,代码行数:23,代码来源:pycrown.py

示例7: filter

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import median_filter [as 别名]
def filter(self, cov, *args, **kwargs):
        cdim = cov.shape
        npol = cdim[0] // 2
        c_int = lambda n: cov[n, n, ...].real

        max_coh = np.zeros(cdim[2:], dtype='f8')
        inten = np.zeros(cdim[2:], dtype='f8')
        for n in range(npol):
            coh = np.abs(cov[n, n + npol, ...]) / np.sqrt(c_int(n) * c_int(n + npol))
            up_mask = (coh > max_coh)
            max_coh = (1 - up_mask) * max_coh + up_mask * coh
            inten = (1 - up_mask) * inten + 0.5 * up_mask * (c_int(n) + c_int(n + npol))

        mask = np.asarray((inten > self.noise) * (max_coh < self.coh_thresh), dtype='u1')

        return median_filter(mask, 3, mode='constant', cval=0) 
开发者ID:birgander2,项目名称:PyRAT,代码行数:18,代码来源:ChangeDet.py

示例8: median_filter

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import median_filter [as 别名]
def median_filter(X, M=8):
    """Median filter along the first axis of the feature matrix X."""
    for i in range(X.shape[1]):
        X[:, i] = filters.median_filter(X[:, i], size=M)
    return X 
开发者ID:urinieto,项目名称:msaf,代码行数:7,代码来源:segmenter.py

示例9: _test_single

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import median_filter [as 别名]
def _test_single(dshape, size , cval = 0., dtype = np.float32, skip_assert = False):
    d = np.random.randint(0, 40, dshape).astype(dtype)*0

    out1 = spf.median_filter(d, size, mode = "constant", cval = cval)
    out2 = median_filter(d, size, cval=cval)

    print(("shape: %s \tsize: %s\tcval: %.2f\tdtype: %s\tdifference: %.2f" % (dshape, size,cval, dtype,np.amax(np.abs(out1 - out2)))))
    if not skip_assert:
        npt.assert_almost_equal(out1,out2, decimal = 5)
    return out1, out2 
开发者ID:maweigert,项目名称:gputools,代码行数:12,代码来源:test_median.py

示例10: median_filter_all_colours

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import median_filter [as 别名]
def median_filter_all_colours(im_small, window_size):
    """
    Applies a median filer to all colour channels
    """
    ims = []
    for d in range(3):
        im_conv_d = median_filter(im_small[:,:,d], size=(window_size,window_size))
        ims.append(im_conv_d)

    im_conv = np.stack(ims, axis=2).astype("uint8")
    
    return im_conv 
开发者ID:misgod,项目名称:fast-neural-style-keras,代码行数:14,代码来源:transform.py

示例11: compare_pyfunc_median_filter_with_direct_call

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import median_filter [as 别名]
def compare_pyfunc_median_filter_with_direct_call(self):
        with self.test_session() as sess:
            test_input = np.random.random((10, 9)).astype(np.float32)
            test_kernel = (3, 3)
            test_input_tf = tf.convert_to_tensor(test_input)
            filter_result_tf = grasp_dataset_median_filter(test_input_tf, test_kernel[0], test_kernel[1])
            filter_result_np = median_filter(test_input, test_kernel)
            filter_result_tf = sess.run(filter_result_tf)
            self.assertAllEqual(filter_result_tf, filter_result_np) 
开发者ID:jhu-lcsr,项目名称:costar_plan,代码行数:11,代码来源:test_median_filter.py

示例12: compute_snr

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import median_filter [as 别名]
def compute_snr(power_2d, fractional_window_size=0.05):
    """
    Extract the central region of the 2D Fourier transform

    Parameters
    ----------
    power_2d : numpy array
        The 2D Fourier transform of the data
    fractional_window_size : float
        Median filter window size as a fraction of the 1D power array

    Returns
    -------
    snr : numpy array
        The 1D SNR
    """
    power = np.median(power_2d, axis=0)
    p2p_scatter = abs(power[1:] - power[:-1])
    power = power[1:]  # Throw away DC term

    # Median filter
    window_size = get_odd_integer(fractional_window_size * len(power))
    continuum = median_filter(power, size=window_size)
    pixel_to_pixel_scatter = median_filter(p2p_scatter, size=window_size)
    snr = (power - continuum) / pixel_to_pixel_scatter

    # Also divide out the global scatter for any residual structure that was not removed with the median filter
    global_scatter = robust_standard_deviation(snr)
    snr /= global_scatter

    return snr 
开发者ID:LCOGT,项目名称:banzai,代码行数:33,代码来源:pattern_noise.py

示例13: deprocess_img_and_save

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import median_filter [as 别名]
def deprocess_img_and_save(img, filename):
    """Undo pre-processing on an image, and save it."""
    img = img[0, :, :, :]
    add_imagenet_mean(img)
    img = img[::-1].transpose((1, 2, 0))
    img = np.clip(img, 0, 255).astype(np.uint8)
    img = median_filter(img, size=(3, 3, 1))
    try:
        imsave(filename, img)
    except OSError as e:
        print(e)
        sys.exit(1) 
开发者ID:jayanthkoushik,项目名称:neural-style,代码行数:14,代码来源:utils.py

示例14: __call__

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import median_filter [as 别名]
def __call__(self, data, num_semg_row, num_semg_col, **kargs):
        return np.array([median_filter(image, 3).ravel() for image
                         in data.reshape(-1, num_semg_row, num_semg_col)]) 
开发者ID:Answeror,项目名称:srep,代码行数:5,代码来源:preprocess.py

示例15: _csl_cut

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import median_filter [as 别名]
def _csl_cut(data, framerate):
    window = int(np.round(150 * framerate / 2048))
    data = data[:len(data) // window * window].reshape(-1, 150, data.shape[1])
    rms = np.sqrt(np.mean(np.square(data), axis=1))
    rms = [median_filter(image, 3).ravel() for image in rms.reshape(-1, 24, 7)]
    rms = np.mean(rms, axis=1)
    threshold = np.mean(rms)
    mask = rms > threshold
    for i in range(1, len(mask) - 1):
        if not mask[i] and mask[i - 1] and mask[i + 1]:
            mask[i] = True
    from .. import utils
    begin, end = max(utils.continuous_segments(mask),
                     key=lambda s: (mask[s[0]], s[1] - s[0]))
    return begin * window, end * window 
开发者ID:Answeror,项目名称:srep,代码行数:17,代码来源:preprocess.py


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