本文整理汇总了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
示例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
示例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
示例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
示例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
示例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))
示例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))
示例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))
示例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))
示例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))
示例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
示例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
示例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
示例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
示例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)