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


Python ndimage.gaussian_filter函数代码示例

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


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

示例1: whiten

def whiten(image):
    
    #return image
    
    tmp = image - image.mean()
    return tmp / numpy.std(tmp)
   
    if image.ndim > 3:
        raise TypeError('Not more than 3 dimensions supported')

    if image.ndim == 3:
        tmp = numpy.empty_like(image)
        for c in range(image.shape[2]):
            tmp[:, :, c] = whiten(image[:, :, c])

        result = numpy.zeros_like(image)
        for c1 in range(image.shape[2]):
            for c2 in range(image.shape[2]):
                if c1 == c2:
                    result[:, :, c1] += tmp[:, :, c2]
                else:
                    result[:, :, c1] -= tmp[:, :, c2]

        return result

    sigma1 = 0.2
    img1 = ndimage.gaussian_filter(image, sigma1)
    sigma2 = 5 * sigma1
    img2 = ndimage.gaussian_filter(image, sigma2)
    result = img1 - img2
    return result
开发者ID:marcelo-borghetti,项目名称:sampleCode,代码行数:31,代码来源:ImageProcessingUtil.py

示例2: mkData

def mkData():
    global data, cache, ui
    dtype = (ui.dtypeCombo.currentText(), ui.rgbCheck.isChecked())
    if dtype not in cache:
        if dtype[0] == 'uint8':
            dt = np.uint8
            loc = 128
            scale = 64
            mx = 255
        elif dtype[0] == 'uint16':
            dt = np.uint16
            loc = 4096
            scale = 1024
            mx = 2**16
        elif dtype[0] == 'float':
            dt = np.float
            loc = 1.0
            scale = 0.1
        
        if ui.rgbCheck.isChecked():
            data = np.random.normal(size=(20,512,512,3), loc=loc, scale=scale)
            data = ndi.gaussian_filter(data, (0, 6, 6, 0))
        else:
            data = np.random.normal(size=(20,512,512), loc=loc, scale=scale)
            data = ndi.gaussian_filter(data, (0, 6, 6))
        if dtype[0] != 'float':
            data = np.clip(data, 0, mx)
        data = data.astype(dt)
        cache[dtype] = data
        
    data = cache[dtype]
    updateLUT()
开发者ID:3rdcycle,项目名称:pyqtgraph,代码行数:32,代码来源:VideoSpeedTest.py

示例3: test_gaussian_filter

def test_gaussian_filter():
    # Test gaussian filter with np.float16
    # gh-8207
    data = np.array([1],dtype = np.float16)
    sigma = 1.0
    with assert_raises(RuntimeError):
        sndi.gaussian_filter(data,sigma)
开发者ID:BranYang,项目名称:scipy,代码行数:7,代码来源:test_filters.py

示例4: smooth_corrected

def smooth_corrected(z, mask, w_smooth):
     mask1=snd.gaussian_filter(np.float32(mask), w_smooth, mode="constant", cval=0)
     ztemp=np.nan_to_num(z)
     ztemp[mask==0]=0.0
     zs=snd.gaussian_filter(ztemp, w_smooth, mode="constant", cval=0)
     zs[mask1>0]=zs[mask1>0]/mask1[mask1>0]
     return zs, mask1
开发者ID:SmithB,项目名称:stereo_script,代码行数:7,代码来源:dem_filter.py

示例5: _process

    def _process(self, img):
        for c in xrange(3):
            channel = img[:, :, c]
            gaussian_filter(channel, output=channel, sigma=self._sigma)
            img[:, :, c] = channel

        return img
开发者ID:jason2506,项目名称:imeffect,代码行数:7,代码来源:basic.py

示例6: density_to_sim_data

def density_to_sim_data(density, out=None):
    """
    Takes a 2D image input, returns a 4D SIM dataset output
    """
    if out == None:
        sim_data = np.zeros(
            (num_rotations, num_phases) + density.shape, dtype=np.float64)
    else:
        sim_data = out

    """
    Construct the illumination pattern
    """
    illumination = generate_illumination(density)
    sim_data_to_visualization(illumination, 'illumination.tif')

    """
    Simulate the imaging process: multiply by the illumination, and blur
    """
    for t in range(num_rotations):
        for p in range(num_phases):
            sim_data[t, p, :, :] = illumination[t, p, :, :] * density
            gaussian_filter(sim_data[t, p, :, :],
                            sigma=emission_sigma,
                            output=sim_data[t, p, :, :])
    return sim_data
开发者ID:ardekani,项目名称:iterative-fusion,代码行数:26,代码来源:decon_sim_sinusoidal.py

示例7: loss

 def loss(self, H): 
     if not hasattr(self, 'sigma'): 
         self.sigma = .05*np.array(H.shape)
     npts = nonzero(self.npoints(H))
     Hs = H/npts
     gaussian_filter(Hs, sigma=self.sigma, mode='constant', output=Hs)
     return dist2loss(Hs)
开发者ID:bergtholdt,项目名称:nipy,代码行数:7,代码来源:similarity_measures.py

示例8: blur_image

def blur_image(img):
    '''Return the blurred image that's used when sampling'''
    blur = np.zeros(list(img.shape)+[2], img.dtype)
    for z in range(img.shape[2]):
        blur[:,:,z, 0] = laplace(gaussian_filter(img[:,:,z], 3))
        blur[:,:,z, 1] = gaussian_filter(img[:,:,z], 5)
    return blur
开发者ID:LeeKamentsky,项目名称:isbi_challenge,代码行数:7,代码来源:extract_features.py

示例9: compute_harris_response

def compute_harris_response(image, eps=1e-6):
    """ compute the Harris corner detector response function
        for each pixel in the image"""

    # derivatives
    image = ndimage.gaussian_filter(image, 1)
    imx = ndimage.sobel(image, axis=0, mode='constant')
    imy = ndimage.sobel(image, axis=1, mode='constant')

    Wxx = ndimage.gaussian_filter(imx * imx, 1.5, mode='constant')
    Wxy = ndimage.gaussian_filter(imx * imy, 1.5, mode='constant')
    Wyy = ndimage.gaussian_filter(imy * imy, 1.5, mode='constant')

    # determinant and trace
    Wdet = Wxx * Wyy - Wxy ** 2
    Wtr = Wxx + Wyy
    harris = Wdet / (Wtr + eps)

    # Non maximum filter of size 3
    harris_max = ndimage.maximum_filter(harris, 3, mode='constant')
    harris *= harris == harris_max
    # Remove the image corners
    harris[:3] = 0
    harris[-3:] = 0
    harris[:, :3] = 0
    harris[:, -3:] = 0

    return harris
开发者ID:NelleV,项目名称:ROVAR,代码行数:28,代码来源:harris.py

示例10: generate_surface_from_stack

def generate_surface_from_stack(stack, sd=(10, 10, 10), surface_blur_sd=5):
    """Return a 2D image encoding a height map, generated from the input stack.
    The image is generated by first blurring the stack, then taking the z index
    of the brightest point for each X, Y location. The resultant surface is
    then smoothed with a gaussian filter.

    sd: standard deviation in each direction
    surface_blur_sd: standard deviation of smoothing applied to 2D surface."""


    ydim, xdim, zdim = stack.shape
    pad_val = 5
    padding = pad_val * 2
    padded_stack = np.zeros((ydim + padding, xdim + padding, zdim + padding),
                            dtype=stack.dtype)
    start = pad_val
    end_add = pad_val
    padded_stack[start:ydim+end_add, start:xdim+end_add, start:zdim+end_add] = stack
    smoothed_stack = nd.gaussian_filter(padded_stack, sd)
    cropped_stack = smoothed_stack[start:ydim+end_add, start:xdim+end_add, start:zdim+end_add]
    raw_surface = np.argmax(cropped_stack, 2)
    raw_surface[np.logical_and(raw_surface==0, cropped_stack[:,:,0] == 0)] = zdim-1
    smoothed_surface = nd.gaussian_filter(raw_surface, surface_blur_sd)

    return smoothed_surface
开发者ID:JIC-Image-Analysis,项目名称:leaf-cell-polarisation-tensors,代码行数:25,代码来源:gaussproj.py

示例11: preproc_dog

def preproc_dog(bg):
    """test low level image filter
    """

    #special dependencies
    from scipy.ndimage import gaussian_filter
    from pyrankfilter import rankfilter,__version__

    bg = bg.astype(float)
    f1 = gaussian_filter(bg,sigma=14.5)
    f2 = gaussian_filter(bg,sigma=15)

    f = ((f1-f2+3)*10).astype('uint8')

    loc_max = rankfilter(f,'highest',20,infSup=[0,0])

    r = bg.copy()
    r[loc_max>0]=0

    plt.figure()
    plt.subplot(2,2,1)
    plt.imshow(bg)
    plt.subplot(2,2,2)
    plt.imshow(f)
    plt.colorbar()
    plt.subplot(2,2,3)
    plt.imshow(loc_max)
    plt.subplot(2,2,4)
    plt.imshow(r)
    plt.show()
开发者ID:odebeir,项目名称:ivctrack,代码行数:30,代码来源:grid_assays.py

示例12: tantriggs

    def tantriggs(self, x, alpha=0.1,gamma=0.2,sigma0=1,sigma1=2,tau=10.0):
        x = np.array(x, dtype=np.float32)
        x = np.power(x, gamma)
        s0 = 3*sigma0
        s1 = 3*sigma1
        if ((s0%2)==0):
            s0+=1
        if ((s1%2)==0):
            s1+=1

        x = np.asarray(
            ndimage.gaussian_filter(x, sigma0) - ndimage.gaussian_filter(x, sigma1)
            )

        x = x / np.power(
            np.mean(np.power(np.abs(x), alpha)),
            1.0 / alpha
            )
        x = x / np.power(
                np.mean(
                    np.power(
                        np.minimum(np.abs(x), tau),
                        alpha
                    )
                ),
                1.0 / alpha
            )

        x = np.tanh(x / tau) * tau
        x = cv2.normalize(x,x,-220,0,cv2.NORM_MINMAX)
        return np.array(x, np.uint8)
开发者ID:gat3way,项目名称:ocv,代码行数:31,代码来源:facerecognition.py

示例13: nan_gaussian_filter

def nan_gaussian_filter(X, sigma, keep_nans=False, gf_kwargs=dict()):
    """Equivalent to scipy.ndimage.gaussian_filter, but allows NaNs

    For inputs see original function

    if keep_nans is True, then output has NaNs everywhere input had nans

    http://stackoverflow.com/questions/18697532/
    gaussian-filtering-a-image-with-nan-in-python"""
    nanX = np.isnan(X)

    X1 = X.copy()
    X1[nanX] = 0
    X1_filtered = gaussian_filter(X1, sigma, **gf_kwargs)

    X2 = np.ones_like(X)
    X2[nanX] = 0
    X2_filtered = gaussian_filter(X2, sigma, **gf_kwargs)

    out = X1_filtered/X2_filtered

    if keep_nans:
        out[nanX] = np.nan

    return out
开发者ID:hugke729,项目名称:MyScripts,代码行数:25,代码来源:MyInterp.py

示例14: sharpen

def sharpen(Xs,ys,sigma1=3,sigma2=1,alpha=30,ratio=0.6,t=None):
    print "sharpening images..."

    if ratio > 1.0:
        print "Do you really want a ratio of %f for sharpen?" % ratio
        print "Every images produced will always be similar"

    rand_list = randomindex(Xs.shape[0]*ratio,Xs.shape[0])
    Xs = Xs[rand_list]
    ys = ys[rand_list]

    tx = []
    ty = []

    for X, y in zip(Xs,ys):
        blurred_l = ndimage.gaussian_filter(X, sigma1)

        filter_blurred_l = ndimage.gaussian_filter(blurred_l, sigma2)
        sharpened = blurred_l + alpha * (blurred_l - filter_blurred_l)

        tx.append(sharpened)
        ty.append(y)

        if t: t.print_update(1)

    return np.array(tx), np.array(ty)
开发者ID:Kerkil,项目名称:ift6266kaggle,代码行数:26,代码来源:__init__.py

示例15: PlotProfile

def PlotProfile(label1, label2, data1, data2, filename, smooth, binsz):
    plt.clf()
    plt.figure(figsize=(5,4))
    plt.rc('text', usetex=True)
    plt.rc('font', family='serif')
    
    counts1 = np.append(data1['FLUX'].data/(EXPOSURE*PIXEL_SA), 0)
    glats1 = np.append(data1['GLAT_MIN'][0], data1['GLAT_MAX'].data)

    profile1 = np.histogram(glats1, bins=np.sort(glats1), weights=counts1)
    xstep=binsz
    y_smooth_1 = gaussian_filter(profile1[0], smooth / xstep)
    print y_smooth_1.mean()
    
    counts2 = np.append(data2['FLUX'].data/(EXPOSURE*PIXEL_SA*(data2['FLUX'].data.size())), 0)
    glats2 = np.append(data2['GLAT_MIN'][0], data2['GLAT_MAX'].data)

    profile2 = np.histogram(glats2, bins=np.sort(glats2), weights=counts2)
    xstep=binsz
    y_smooth_2 = gaussian_filter(profile2[0], smooth / xstep)
    print y_smooth_2.mean()
    
    x1 = 0.5 * (glats1[1:] + glats1[:-1])
    plt.plot(x1, y_smooth_1, label='{0}'.format(label1))
    plt.plot(x1, y_smooth_2, label='{0}'.format(label2))
    plt.hlines(0, LatLow+binsz, LatHigh-binsz)
    plt.xlabel(r'Galactic Latitude/$deg$', fontsize=10)
    plt.ylabel(r'Surface Brightness/ph cm$^{-2}$ s$^{-1} sr^{-1}$', fontsize=10)
    plt.xlim([LatLow+binsz, LatHigh-binsz])
    plt.tick_params(axis='x', labelsize=10)
    plt.grid(b=True, which='major', color='0.75', linewidth=0.5)
    plt.legend(prop={'size':8})
    plt.savefig(filename)
开发者ID:ellisowen,项目名称:SciNeGHE_scripts,代码行数:33,代码来源:data_latitude_profile.py


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