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


Python filters.gaussian_filter1d方法代码示例

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


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

示例1: pick_peaks

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

示例2: computeForwardPrior

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import gaussian_filter1d [as 别名]
def computeForwardPrior(self, posterior, t):
        """
        Compute new prior from old posterior (moving forwards in time).

        Args:
            posterior(ndarray): Parameter distribution from current time step
            t(int): integer time step

        Returns:
            ndarray: Prior parameter distribution for subsequent time step
        """
        axisToTransform = self.study.observationModel.parameterNames.index(self.selectedParameter)
        normedSigma = self.hyperParameterValues[0]/self.latticeConstant[axisToTransform]
        
        if normedSigma > 0.:
            newPrior = gaussian_filter1d(posterior, normedSigma, axis=axisToTransform)
        else:
            newPrior = posterior.copy()
        
        return newPrior 
开发者ID:christophmark,项目名称:bayesloop,代码行数:22,代码来源:transitionModels.py

示例3: stackspectrum

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import gaussian_filter1d [as 别名]
def stackspectrum(self, time, throttle, trace, window):
        ### calculates spectrogram from stack of windows against throttle.
        # slicing off last 2s to get rid of landing
        gyro = trace[:-int(Trace.noise_superpos*2./Trace.noise_framelen),:] * window
        thr = throttle[:-int(Trace.noise_superpos*2./Trace.noise_framelen),:] * window
        time = time[:-int(Trace.noise_superpos*2./Trace.noise_framelen),:]

        freq, spec = self.spectrum(time[0], gyro)

        weights = abs(spec.real)
        avr_thr = np.abs(thr).max(axis=1)

        hist2d=self.hist2d(avr_thr, freq,weights,[101,len(freq)/4])

        filt_width = 3  # width of gaussian smoothing for hist data
        hist2d_sm = gaussian_filter1d(hist2d['hist2d_norm'], filt_width, axis=1, mode='constant')

        # get max value in histogram >100hz
        thresh = 100.
        mask = self.to_mask(freq[:-1:4].clip(thresh-1e-9,thresh))
        maxval = np.max(hist2d_sm.transpose()*mask)

        return {'throt_hist_avr':hist2d['throt_hist'],'throt_axis':hist2d['throt_scale'],'freq_axis':freq[::4],
                'hist2d_norm':hist2d['hist2d_norm'], 'hist2d_sm':hist2d_sm, 'hist2d':hist2d['hist2d'], 'max':maxval} 
开发者ID:PX4,项目名称:flight_review,代码行数:26,代码来源:pid_analysis.py

示例4: smooth_bbox_params

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import gaussian_filter1d [as 别名]
def smooth_bbox_params(bbox_params, kernel_size=11, sigma=8):
    """
    Applies median filtering and then gaussian filtering to bounding box
    parameters.

    Args:
        bbox_params (Nx3): [cx, cy, scale].
        kernel_size (int): Kernel size for median filtering (must be odd).
        sigma (float): Sigma for gaussian smoothing.

    Returns:
        Smoothed bounding box parameters (Nx3).
    """
    smoothed = np.array([signal.medfilt(param, kernel_size)
                         for param in bbox_params.T]).T
    return np.array([gaussian_filter1d(traj, sigma) for traj in smoothed.T]).T 
开发者ID:akanazawa,项目名称:human_dynamics,代码行数:18,代码来源:smooth_bbox.py

示例5: visualize_scroll

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import gaussian_filter1d [as 别名]
def visualize_scroll(y):
    """Effect that originates in the center and scrolls outwards"""
    global p
    y = y**2.0
    gain.update(y)
    y /= gain.value
    y *= 255.0
    r = int(np.max(y[:len(y) // 3]))
    g = int(np.max(y[len(y) // 3: 2 * len(y) // 3]))
    b = int(np.max(y[2 * len(y) // 3:]))
    # Scrolling effect window
    p[:, 1:] = p[:, :-1]
    p *= 0.98
    p = gaussian_filter1d(p, sigma=0.2)
    # Create new color originating at the center
    p[0, 0] = r
    p[1, 0] = g
    p[2, 0] = b
    # Update the LED strip
    return np.concatenate((p[:, ::-1], p), axis=1) 
开发者ID:scottlawsonbc,项目名称:audio-reactive-led-strip,代码行数:22,代码来源:visualization.py

示例6: __post_process

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import gaussian_filter1d [as 别名]
def __post_process(self, result, sigma):
        new_res =  gaussian_filter1d(result, sigma=sigma, axis=0)
        return new_res 
开发者ID:yabufarha,项目名称:anticipating-activities,代码行数:5,代码来源:cnn.py

示例7: gc_normalize

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import gaussian_filter1d [as 别名]
def gc_normalize(self, chrom, coverage):
    """ Apply a model to normalize for GC content.

        In
         chrom (str): Chromosome
         coverage ([float]): Coverage array
         pseudocount (int): Coverage pseudocount.

        Out
         model (sklearn object): To control for GC%.
        """

    # trim chromosome strand
    if self.stranded and chrom[-1] in '+-':
      chrom = chrom[:-1]

    # get sequence
    seq = self.fasta.fetch(chrom)
    assert (len(seq) == len(coverage))

    # compute GC boolean vector
    seq_gc = np.array([nt in 'CG' for nt in seq], dtype='float32')

    # gaussian filter1d
    seq_gc_gauss = gaussian_filter1d(seq_gc, sigma=self.fragment_sd, truncate=3)

    # compute norm quantity
    seq_gc_norm = self.gc_model.predict(seq_gc_gauss[:, np.newaxis])

    # apply it
    return coverage * np.exp(-seq_gc_norm + self.gc_base) 
开发者ID:calico,项目名称:basenji,代码行数:33,代码来源:bam_cov.py

示例8: smooth

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import gaussian_filter1d [as 别名]
def smooth(y):
    return gaussian_filter1d(y, sigma=0.6) 
开发者ID:lx10077,项目名称:fedavgpy,代码行数:4,代码来源:plot_E.py

示例9: skew_detection

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import gaussian_filter1d [as 别名]
def skew_detection(image_gray):
    h, w = image_gray.shape[:2]
    eigen = cv2.cornerEigenValsAndVecs(image_gray,12, 5)
    angle_sur = np.zeros(180,np.uint)
    eigen = eigen.reshape(h, w, 3, 2)
    flow = eigen[:,:,2]
    vis = image_gray.copy()
    vis[:] = (192 + np.uint32(vis)) / 2
    d = 12
    points =  np.dstack( np.mgrid[d/2:w:d, d/2:h:d] ).reshape(-1, 2)
    for x, y in points:
        vx, vy = np.int32(flow[int(y), int(x)]*d)
        # cv2.line(rgb, (x-vx, y-vy), (x+vx, y+vy), (0, 355, 0), 1, cv2.LINE_AA)
        ang = angle(vx,vy)
        angle_sur[(ang+180)%180] +=1

    # torr_bin = 30
    angle_sur = angle_sur.astype(np.float)
    angle_sur = (angle_sur-angle_sur.min())/(angle_sur.max()-angle_sur.min())
    angle_sur = filters.gaussian_filter1d(angle_sur,5)
    skew_v_val =  angle_sur[20:180-20].max()
    skew_v = angle_sur[30:180-30].argmax() + 30
    skew_h_A = angle_sur[0:30].max()
    skew_h_B = angle_sur[150:180].max()
    skew_h = 0
    if (skew_h_A > skew_v_val*0.3 or skew_h_B > skew_v_val*0.3):
        if skew_h_A>=skew_h_B:
            skew_h = angle_sur[0:20].argmax()
        else:
            skew_h = - angle_sur[160:180].argmax()
    return skew_h,skew_v 
开发者ID:fanghon,项目名称:lpr,代码行数:33,代码来源:deskew.py

示例10: smooth_bbox_params

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import gaussian_filter1d [as 别名]
def smooth_bbox_params(bbox_params, kernel_size=11, sigma=8):
    """
    Applies median filtering and then gaussian filtering to bounding box
    parameters.
    Args:
        bbox_params (Nx3): [cx, cy, scale].
        kernel_size (int): Kernel size for median filtering (must be odd).
        sigma (float): Sigma for gaussian smoothing.
    Returns:
        Smoothed bounding box parameters (Nx3).
    """
    smoothed = np.array([signal.medfilt(param, kernel_size)
                         for param in bbox_params.T]).T
    return np.array([gaussian_filter1d(traj, sigma) for traj in smoothed.T]).T 
开发者ID:jasonyzhang,项目名称:phd,代码行数:16,代码来源:smooth_bbox.py

示例11: smooth

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import gaussian_filter1d [as 别名]
def smooth(v, width=1, temporal=False):
    """
    smoothes a ndarray with a Gaussian blur.

    Parameters
    ----------
    v: np.ndarray [shape=(nb_frames, ...)]
        input array

    sigma: int [scalar]
        lengthscale of the gaussian blur

    temporal: boolean
        if True, will smooth only along time through 1d blur. Will use a
        multidimensional Gaussian blur otherwise.

    Returns
    -------
    result: np.ndarray [shape=(nb_frames, ...)]
        filtered array

    """
    if temporal:
        return gaussian_filter1d(v, sigma=width, axis=0)
    else:
        return gaussian_filter(v, sigma=width, truncate=width) 
开发者ID:sigsep,项目名称:norbert,代码行数:28,代码来源:contrib.py

示例12: smooth_spectra

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import gaussian_filter1d [as 别名]
def smooth_spectra(xarr, farr, sigma=3, nkern=20):
    """Given a xarr and flux, smooth the spectrum"""
    xkern = np.arange(nkern)
    kern = np.exp(-(xkern - 0.5 * nkern) ** 2 / (sigma) ** 2)

    return gaussian_filter1d(farr, sigma) 
开发者ID:crawfordsm,项目名称:specidentify,代码行数:8,代码来源:spectools.py

示例13: cluster_formation_alignment_fsc__by_global_maximum

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import gaussian_filter1d [as 别名]
def cluster_formation_alignment_fsc__by_global_maximum(self, dj, op=None):
    if ('debug' not in op):
        op['debug'] = False
    dj = copy.deepcopy(dj)
    djm = defaultdict(list)
    for r in dj:
        if ('template' not in r):
            continue
        djm[str(r['template']['subtomogram'])].append(r)
    djm_org = copy.deepcopy(djm)
    for k in djm:
        djmt = djm[k]
        djmt = sorted(djmt, key=(lambda _: float(_['score'])), reverse=True)
        if (('max_expansion_size' in op) and (len(djmt) > op['max_expansion_size'])):
            djmt = djmt[:op['max_expansion_size']]
        djm[k] = djmt
    ssnr_sequential_op = copy.deepcopy(op['ssnr_sequential'])
    ssnr_sequential_op['n_chunk'] = op['n_chunk']
    ssnr_s = SS.ssnr_sequential_parallel(self=self, data_json_dict=djm, op=ssnr_sequential_op)
    fsc_sum = {}
    for k in ssnr_s:
        fsc_sum[k] = N.array([N.sum(_) for _ in ssnr_s[k]['fsc']])
    import scipy.ndimage.filters as SDF
    if ('gaussian_smooth_sigma' in op):
        for k in fsc_sum:
            fsc_sum[k] = SDF.gaussian_filter1d(fsc_sum[k], op['gaussian_smooth_sigma'])
    if ('min_expansion_size' in op):
        for k in copy.deepcopy(list(fsc_sum.keys())):
            if (len(fsc_sum[k]) < op['min_expansion_size']):
                del fsc_sum[k]
                continue
            fsc_sum[k][:op['min_expansion_size']] = (N.min(fsc_sum[k]) - 1)
    dj_gm = {}
    for k in fsc_sum:
        i = N.argmax(fsc_sum[k])
        if op['debug']:
            print('template', k, 'original subtomogram num', len(djm_org[k]), 'global maximum', i)
        dj_gm[k] = {'k': k, 'i': i, 'data_json': copy.deepcopy(djm[k][:(i + 1)]), 'fsc': ssnr_s[k]['fsc'][i], 'fsc_sum': fsc_sum[k][i], }
    return {'dj_gm': dj_gm, 'djm': djm, 'ssnr_s': ssnr_s, } 
开发者ID:xulabs,项目名称:aitom,代码行数:41,代码来源:util.py

示例14: wiener_deconvolution

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import gaussian_filter1d [as 别名]
def wiener_deconvolution(self, input, output, cutfreq):      # input/output are two-dimensional
        pad = 1024 - (len(input[0]) % 1024)                     # padding to power of 2, increases transform speed
        input = np.pad(input, [[0,0],[0,pad]], mode='constant')
        output = np.pad(output, [[0, 0], [0, pad]], mode='constant')
        H = np.fft.fft(input, axis=-1)
        G = np.fft.fft(output,axis=-1)
        freq = np.abs(np.fft.fftfreq(len(input[0]), self.dt))
        sn = self.to_mask(np.clip(np.abs(freq), cutfreq-1e-9, cutfreq))
        len_lpf=np.sum(np.ones_like(sn)-sn)
        sn=self.to_mask(gaussian_filter1d(sn,len_lpf/6.))
        sn= 10.*(-sn+1.+1e-9)       # +1e-9 to prohibit 0/0 situations
        Hcon = np.conj(H)
        deconvolved_sm = np.real(np.fft.ifft(G * Hcon / (H * Hcon + 1./sn),axis=-1))
        return deconvolved_sm 
开发者ID:PX4,项目名称:flight_review,代码行数:16,代码来源:pid_analysis.py

示例15: weighted_mode_avr

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import gaussian_filter1d [as 别名]
def weighted_mode_avr(self, values, weights, vertrange, vertbins):
        ### finds the most common trace and std
        threshold = 0.5  # threshold for std calculation
        filt_width = 7  # width of gaussian smoothing for hist data

        resp_y = np.linspace(vertrange[0], vertrange[-1], vertbins, dtype=np.float64)
        times = np.repeat(np.array([self.time_resp],dtype=np.float64), len(values), axis=0)
        weights = np.repeat(weights, len(values[0]))

        hist2d = np.histogram2d(times.flatten(), values.flatten(),
                                range=[[self.time_resp[0], self.time_resp[-1]], vertrange],
                                bins=[len(times[0]), vertbins], weights=weights.flatten())[0].transpose()
        ### shift outer edges by +-1e-5 (10us) bacause of dtype32. Otherwise different precisions lead to artefacting.
        ### solution to this --> somethings strage here. In outer most edges some bins are doubled, some are empty.
        ### Hence sometimes produces "divide by 0 error" in "/=" operation.

        if hist2d.sum():
            hist2d_sm = gaussian_filter1d(hist2d, filt_width, axis=0, mode='constant')
            hist2d_sm /= np.max(hist2d_sm, 0)


            pixelpos = np.repeat(resp_y.reshape(len(resp_y), 1), len(times[0]), axis=1)
            avr = np.average(pixelpos, 0, weights=hist2d_sm * hist2d_sm)
        else:
            hist2d_sm = hist2d
            avr = np.zeros_like(self.time_resp)
        # only used for monochrome error width
        hist2d[hist2d <= threshold] = 0.
        hist2d[hist2d > threshold] = 0.5 / (vertbins / (vertrange[-1] - vertrange[0]))

        std = np.sum(hist2d, 0)

        return avr, std, [self.time_resp, resp_y, hist2d_sm]

    ### calculates weighted avverage and resulting errors 
开发者ID:PX4,项目名称:flight_review,代码行数:37,代码来源:pid_analysis.py


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