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


Python filters.gaussian方法代碼示例

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


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

示例1: glass_blur

# 需要導入模塊: from skimage import filters [as 別名]
# 或者: from skimage.filters import gaussian [as 別名]
def glass_blur(x, severity=1):
    # sigma, max_delta, iterations
    c = [(0.7, 1, 2), (0.9, 2, 1), (1, 2, 3), (1.1, 3, 2), (1.5, 4, 2)][severity - 1]

    x = np.uint8(gaussian(np.array(x) / 255., sigma=c[0], multichannel=True) * 255)

    # locally shuffle pixels
    for i in range(c[2]):
        for h in range(224 - c[1], c[1], -1):
            for w in range(224 - c[1], c[1], -1):
                dx, dy = np.random.randint(-c[1], c[1], size=(2,))
                h_prime, w_prime = h + dy, w + dx
                # swap
                x[h, w], x[h_prime, w_prime] = x[h_prime, w_prime], x[h, w]

    return np.clip(gaussian(x / 255., sigma=c[0], multichannel=True), 0, 1) * 255 
開發者ID:hendrycks,項目名稱:robustness,代碼行數:18,代碼來源:corruptions.py

示例2: glass_blur

# 需要導入模塊: from skimage import filters [as 別名]
# 或者: from skimage.filters import gaussian [as 別名]
def glass_blur(x, severity=1):
    # sigma, max_delta, iterations
    c = [(0.05,1,1), (0.25,1,1), (0.4,1,1), (0.25,1,2), (0.4,1,2)][severity - 1]

    x = np.uint8(gaussian(np.array(x) / 255., sigma=c[0], multichannel=True) * 255)

    # locally shuffle pixels
    for i in range(c[2]):
        for h in range(32 - c[1], c[1], -1):
            for w in range(32 - c[1], c[1], -1):
                dx, dy = np.random.randint(-c[1], c[1], size=(2,))
                h_prime, w_prime = h + dy, w + dx
                # swap
                x[h, w], x[h_prime, w_prime] = x[h_prime, w_prime], x[h, w]

    return np.clip(gaussian(x / 255., sigma=c[0], multichannel=True), 0, 1) * 255 
開發者ID:hendrycks,項目名稱:robustness,代碼行數:18,代碼來源:make_cifar_c.py

示例3: glass_blur

# 需要導入模塊: from skimage import filters [as 別名]
# 或者: from skimage.filters import gaussian [as 別名]
def glass_blur(x, severity=1):
    # sigma, max_delta, iterations
    c = [(0.1,1,1), (0.5,1,1), (0.6,1,2), (0.7,2,1), (0.9,2,2)][severity - 1]

    x = np.uint8(gaussian(np.array(x) / 255., sigma=c[0], multichannel=True) * 255)

    # locally shuffle pixels
    for i in range(c[2]):
        for h in range(64 - c[1], c[1], -1):
            for w in range(64 - c[1], c[1], -1):
                dx, dy = np.random.randint(-c[1], c[1], size=(2,))
                h_prime, w_prime = h + dy, w + dx
                # swap
                x[h, w], x[h_prime, w_prime] = x[h_prime, w_prime], x[h, w]

    return np.clip(gaussian(x / 255., sigma=c[0], multichannel=True), 0, 1) * 255 
開發者ID:hendrycks,項目名稱:robustness,代碼行數:18,代碼來源:make_tinyimagenet_c.py

示例4: post_process_output

# 需要導入模塊: from skimage import filters [as 別名]
# 或者: from skimage.filters import gaussian [as 別名]
def post_process_output(q_img, cos_img, sin_img, width_img):
    """
    Post-process the raw output of the GG-CNN, convert to numpy arrays, apply filtering.
    :param q_img: Q output of GG-CNN (as torch Tensors)
    :param cos_img: cos output of GG-CNN
    :param sin_img: sin output of GG-CNN
    :param width_img: Width output of GG-CNN
    :return: Filtered Q output, Filtered Angle output, Filtered Width output
    """
    q_img = q_img.cpu().numpy().squeeze()
    ang_img = (torch.atan2(sin_img, cos_img) / 2.0).cpu().numpy().squeeze()
    width_img = width_img.cpu().numpy().squeeze() * 150.0

    q_img = gaussian(q_img, 2.0, preserve_range=True)
    ang_img = gaussian(ang_img, 2.0, preserve_range=True)
    width_img = gaussian(width_img, 1.0, preserve_range=True)

    return q_img, ang_img, width_img 
開發者ID:dougsm,項目名稱:ggcnn,代碼行數:20,代碼來源:common.py

示例5: glass_blur

# 需要導入模塊: from skimage import filters [as 別名]
# 或者: from skimage.filters import gaussian [as 別名]
def glass_blur(x, severity=1):
    # sigma, max_delta, iterations
    c = [(0.7, 1, 2), (0.9, 2, 1), (1, 2, 3), (1.1, 3, 2), (1.5, 4, 2)][
        severity - 1]

    x = np.uint8(
        gaussian(np.array(x) / 255., sigma=c[0], multichannel=True) * 255)
    x_shape = np.array(x).shape

    # locally shuffle pixels
    for i in range(c[2]):
        for h in range(x_shape[0] - c[1], c[1], -1):
            for w in range(x_shape[1] - c[1], c[1], -1):
                dx, dy = np.random.randint(-c[1], c[1], size=(2,))
                h_prime, w_prime = h + dy, w + dx
                # swap
                x[h, w], x[h_prime, w_prime] = x[h_prime, w_prime], x[h, w]

    return np.clip(gaussian(x / 255., sigma=c[0], multichannel=True), 0,
                   1) * 255 
開發者ID:bethgelab,項目名稱:imagecorruptions,代碼行數:22,代碼來源:corruptions.py

示例6: new_crap_AG_SP

# 需要導入模塊: from skimage import filters [as 別名]
# 或者: from skimage.filters import gaussian [as 別名]
def new_crap_AG_SP(x, scale=4, upsample=False):
    xn = np.array(x)
    xorig_max = xn.max()
    xn = xn.astype(np.float32)
    xn /= float(np.iinfo(np.uint8).max)

    lvar = filters.gaussian(xn, sigma=5) + 1e-10
    xn = random_noise(xn, mode='localvar', local_vars=lvar*0.5)

    xn = random_noise(xn, mode='salt', amount=0.005)
    xn = random_noise(xn, mode='pepper', amount=0.005)

    new_max = xn.max()
    x = xn
    if new_max > 0:
        xn /= new_max
    xn *= xorig_max
    multichannel = len(x.shape) > 2

    xn = rescale(xn, scale=1/scale, order=1, multichannel=multichannel)
    return PIL.Image.fromarray(xn.astype(np.uint8)) 
開發者ID:BPHO-Salk,項目名稱:PSSR,代碼行數:23,代碼來源:crappifiers.py

示例7: new_crap

# 需要導入模塊: from skimage import filters [as 別名]
# 或者: from skimage.filters import gaussian [as 別名]
def new_crap(x, scale=4, upsample=False):
    xn = np.array(x)
    xorig_max = xn.max()
    xn = xn.astype(np.float32)
    xn /= float(np.iinfo(np.uint8).max)

    xn = random_noise(xn, mode='salt', amount=0.005)
    xn = random_noise(xn, mode='pepper', amount=0.005)
    lvar = filters.gaussian(xn, sigma=5) + 1e-10
    xn = random_noise(xn, mode='localvar', local_vars=lvar*0.5)
    new_max = xn.max()
    x = xn
    if new_max > 0:
        xn /= new_max
    xn *= xorig_max
    multichannel = len(x.shape) > 2
    x = rescale(x, scale=1/scale, order=1, multichannel=multichannel)
    return PIL.Image.fromarray(x.astype(np.uint8)) 
開發者ID:BPHO-Salk,項目名稱:PSSR,代碼行數:20,代碼來源:crappifiers.py

示例8: fluo_AG_D

# 需要導入模塊: from skimage import filters [as 別名]
# 或者: from skimage.filters import gaussian [as 別名]
def fluo_AG_D(x, scale=4, upsample=False):
    xn = np.array(x)
    xorig_max = xn.max()
    xn = xn.astype(np.float32)
    xn /= float(np.iinfo(np.uint8).max)

    lvar = filters.gaussian(xn, sigma=5) + 1e-10
    xn = random_noise(xn, mode='localvar', local_vars=lvar*0.5)
    new_max = xn.max()
    x = xn
    if new_max > 0:
        xn /= new_max
    xn *= xorig_max
    x_down = npzoom(x, 1/scale, order=1)
    #x_up = npzoom(x_down, scale, order=1)
    return PIL.Image.fromarray(x_down.astype(np.uint8)) 
開發者ID:BPHO-Salk,項目名稱:PSSR,代碼行數:18,代碼來源:crappifiers.py

示例9: fluo_SP_AG_D_sameas_preprint

# 需要導入模塊: from skimage import filters [as 別名]
# 或者: from skimage.filters import gaussian [as 別名]
def fluo_SP_AG_D_sameas_preprint(x, scale=4, upsample=False):
    xn = np.array(x)
    xorig_max = xn.max()
    xn = xn.astype(np.float32)
    xn /= float(np.iinfo(np.uint8).max)
    xn = random_noise(xn, mode='salt', amount=0.005)
    xn = random_noise(xn, mode='pepper', amount=0.005)
    lvar = filters.gaussian(xn, sigma=5) + 1e-10
    xn = random_noise(xn, mode='localvar', local_vars=lvar*0.5)
    new_max = xn.max()
    x = xn
    if new_max > 0:
        xn /= new_max
    xn *= xorig_max
    x_down = npzoom(x, 1/scale, order=1)
    return PIL.Image.fromarray(x_down.astype(np.uint8)) 
開發者ID:BPHO-Salk,項目名稱:PSSR,代碼行數:18,代碼來源:crappifiers.py

示例10: fluo_SP_AG_D_sameas_preprint_rescale

# 需要導入模塊: from skimage import filters [as 別名]
# 或者: from skimage.filters import gaussian [as 別名]
def fluo_SP_AG_D_sameas_preprint_rescale(x, scale=4, upsample=False):
    xn = np.array(x)
    xorig_max = xn.max()
    xn = xn.astype(np.float32)
    xn /= float(np.iinfo(np.uint8).max)
    xn = random_noise(xn, mode='salt', amount=0.005)
    xn = random_noise(xn, mode='pepper', amount=0.005)
    lvar = filters.gaussian(xn, sigma=5) + 1e-10
    xn = random_noise(xn, mode='localvar', local_vars=lvar*0.5)
    new_max = xn.max()
    x = xn
    if new_max > 0:
        xn /= new_max
    xn *= xorig_max
    multichannel = len(x.shape) > 2
    x_down = rescale(x, scale=1/scale, order=1, multichannel=multichannel)
    return PIL.Image.fromarray(x_down.astype(np.uint8)) 
開發者ID:BPHO-Salk,項目名稱:PSSR,代碼行數:19,代碼來源:crappifiers.py

示例11: _my_noise

# 需要導入模塊: from skimage import filters [as 別名]
# 或者: from skimage.filters import gaussian [as 別名]
def _my_noise(x, gauss_sigma:uniform=0.01, pscale:uniform=10):
    xn = x.numpy()
    xorig_max = xn.max()

    xn = random_noise(xn, mode='salt', amount=0.005)
    xn = random_noise(xn, mode='pepper', amount=0.005)
    lvar = filters.gaussian(x, sigma=5) + 1e-10
    xn = random_noise(xn, mode='localvar', local_vars=lvar*0.5)
    #xn = np.random.poisson(xn*pscale)/pscale
    #xn += np.random.normal(0, gauss_sigma*xn.std(), size=x.shape)
    x = x.new(xn)
    new_max = xn.max()
    if new_max > 0:
        xn /= new_max
    xn *= xorig_max
    return x 
開發者ID:BPHO-Salk,項目名稱:PSSR,代碼行數:18,代碼來源:utils.py

示例12: circular_filter_1d

# 需要導入模塊: from skimage import filters [as 別名]
# 或者: from skimage.filters import gaussian [as 別名]
def circular_filter_1d(signal, window_size, kernel='gaussian'):

    """ This function filters circularly the signal inputted with a median filter of inputted size, in this context
    circularly means that the signal is wrapped around and then filtered
    inputs :
        - signal : 1D numpy array
        - window_size : size of the kernel, an int
    outputs :
        - signal_smoothed : 1D numpy array, same size as signal"""

    signal_extended = np.concatenate((signal, signal, signal))  # replicate signal at both ends
    if kernel == 'gaussian':
        signal_extended_smooth = ndimage.gaussian_filter(signal_extended, window_size)  # gaussian
    elif kernel == 'median':
        signal_extended_smooth = medfilt(signal_extended, window_size)  # median filtering
    else:
        raise Exception("Unknow type of kernel")

    signal_smoothed = signal_extended_smooth[len(signal):2*len(signal)]  # truncate back the signal

    return signal_smoothed 
開發者ID:neuropoly,項目名稱:spinalcordtoolbox,代碼行數:23,代碼來源:msct_register.py

示例13: thresh_slide

# 需要導入模塊: from skimage import filters [as 別名]
# 或者: from skimage.filters import gaussian [as 別名]
def thresh_slide(gray, thresh_val, sigma=13):
    """ Threshold gray image to binary image
    Parameters
    ----------
    gray : np.array
        2D gray image.
    thresh_val: float
        Thresholding value.
    smooth_sigma: int
        Gaussian smoothing sigma.
    Returns
    -------
    bw_img: np.array
        Binary image
    """

    # Smooth
    smooth = filters.gaussian(gray, sigma=sigma)
    smooth /= np.amax(smooth)
    # Threshold
    bw_img = smooth < thresh_val

    return bw_img 
開發者ID:PingjunChen,項目名稱:tissueloc,代碼行數:25,代碼來源:locate_tissue.py

示例14: smooth_edge

# 需要導入模塊: from skimage import filters [as 別名]
# 或者: from skimage.filters import gaussian [as 別名]
def smooth_edge(self, data):
        smoothed_label = data['label'].copy()

        for z in range(smoothed_label.shape[0]):
            temp = smoothed_label[z].copy()
            for idx in np.unique(temp):
                if idx != 0:
                    binary = (temp==idx).astype(np.uint8)
                    for _ in range(2):
                        binary = dilation(binary)
                        binary = gaussian(binary, sigma=2, preserve_range=True)
                        binary = dilation(binary)
                        binary = (binary > 0.8).astype(np.uint8)
            
                    temp[np.where(temp==idx)]=0
                    temp[np.where(binary==1)]=idx
            smoothed_label[z] = temp

        data['label'] = smoothed_label
        return data 
開發者ID:zudi-lin,項目名稱:pytorch_connectomics,代碼行數:22,代碼來源:composition.py

示例15: sharpen

# 需要導入模塊: from skimage import filters [as 別名]
# 或者: from skimage.filters import gaussian [as 別名]
def sharpen(img):
    img = img * 1.0
    gauss_out = gaussian(img, sigma=5, multichannel=True)

    alpha = 1.5
    img_out = (img - gauss_out) * alpha + img

    img_out = img_out / 255.0

    mask_1 = img_out < 0
    mask_2 = img_out > 1

    img_out = img_out * (1 - mask_1)
    img_out = img_out * (1 - mask_2) + mask_2
    img_out = np.clip(img_out, 0, 1)
    img_out = img_out * 255
    return np.array(img_out, dtype=np.uint8) 
開發者ID:zllrunning,項目名稱:face-parsing.PyTorch,代碼行數:19,代碼來源:makeup.py


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