本文整理汇总了Python中scipy.ndimage.gaussian_filter方法的典型用法代码示例。如果您正苦于以下问题:Python ndimage.gaussian_filter方法的具体用法?Python ndimage.gaussian_filter怎么用?Python ndimage.gaussian_filter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.ndimage
的用法示例。
在下文中一共展示了ndimage.gaussian_filter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ssim_exact
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import gaussian_filter [as 别名]
def ssim_exact(img1, img2, sd=1.5, C1=0.01**2, C2=0.03**2):
mu1 = gaussian_filter(img1, sd)
mu2 = gaussian_filter(img2, sd)
mu1_sq = mu1 * mu1
mu2_sq = mu2 * mu2
mu1_mu2 = mu1 * mu2
sigma1_sq = gaussian_filter(img1 * img1, sd) - mu1_sq
sigma2_sq = gaussian_filter(img2 * img2, sd) - mu2_sq
sigma12 = gaussian_filter(img1 * img2, sd) - mu1_mu2
ssim_num = ((2 * mu1_mu2 + C1) * (2 * sigma12 + C2))
ssim_den = ((mu1_sq + mu2_sq + C1) * (sigma1_sq + sigma2_sq + C2))
ssim_map = ssim_num / ssim_den
return numpy.mean(ssim_map)
示例2: GaussianFilter
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import gaussian_filter [as 别名]
def GaussianFilter(in_dem, sigma=1, out_file=None):
print("Gaussian filtering ...")
start_time = time.time()
dem = rd.LoadGDAL(in_dem)
no_data = dem.no_data
projection = dem.projection
geotransform = dem.geotransform
gau = ndimage.gaussian_filter(dem, sigma=sigma)
gau = np2rdarray(gau, no_data, projection, geotransform)
print("Run time: {:.4f} seconds".format(time.time() - start_time))
if out_file is not None:
print("Saving dem ...")
rd.SaveGDAL(out_file, gau)
return out_file
return gau
# ##################################### main script
示例3: random_blobs
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import gaussian_filter [as 别名]
def random_blobs(shape, blobdensity, size, roughness=2.0):
from random import randint
from builtins import range # python2 compatible
h, w = shape
numblobs = int(blobdensity * w * h)
mask = np.zeros((h, w), 'i')
for i in range(numblobs):
mask[randint(0, h-1), randint(0, w-1)] = 1
dt = ndi.distance_transform_edt(1-mask)
mask = np.array(dt < size, 'f')
mask = ndi.gaussian_filter(mask, size/(2*roughness))
mask -= np.amin(mask)
mask /= np.amax(mask)
noise = np.random.rand(h, w)
noise = ndi.gaussian_filter(noise, size/(2*roughness))
noise -= np.amin(noise)
noise /= np.amax(noise)
return np.array(mask * noise > 0.5, 'f')
示例4: printlike_fibrous
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import gaussian_filter [as 别名]
def printlike_fibrous(image, blur=1.0, blotches=5e-5, inverted=None):
if inverted:
selector = image
elif inverted is None:
selector = autoinvert(image)
else:
selector = 1 - image
selector = random_blotches(selector, 3*blotches, blotches)
paper = make_multiscale_noise(image.shape, [1.0, 5.0, 10.0, 50.0], weights=[1.0, 0.3, 0.5, 0.3], span=(0.7, 1.0))
paper -= make_fibrous_image(image.shape, 300, 500, 0.01, span=(0.0, 0.25), blur=0.5)
ink = make_multiscale_noise(image.shape, [1.0, 5.0, 10.0, 50.0], span=(0.0, 0.5))
blurred = ndi.gaussian_filter(selector, blur)
printed = blurred * ink + (1-blurred) * paper
if inverted:
return 1 - printed
else:
return printed
示例5: test_generic_laplace01
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import gaussian_filter [as 别名]
def test_generic_laplace01(self):
def derivative2(input, axis, output, mode, cval, a, b):
sigma = [a, b / 2.0]
input = numpy.asarray(input)
order = [0] * input.ndim
order[axis] = 2
return ndimage.gaussian_filter(input, sigma, order,
output, mode, cval)
for type in self.types:
array = numpy.array([[3, 2, 5, 1, 4],
[5, 8, 3, 7, 1],
[5, 6, 9, 3, 5]], type)
output = numpy.zeros(array.shape, type)
tmp = ndimage.generic_laplace(array, derivative2,
extra_arguments=(1.0,), extra_keywords={'b': 2.0})
ndimage.gaussian_laplace(array, 1.0, output)
assert_array_almost_equal(tmp, output)
示例6: filter
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import gaussian_filter [as 别名]
def filter(self, signal):
"""Filter a given signal with a choice of filter type (self.lres_filter).
"""
signal = signal.copy()
filter_size = [1, self.downsamp_t*2-1, self.downsamp_xz*2-1, self.downsamp_xz*2-1]
if self.lres_filter == 'none' or (not self.lres_filter):
output = signal
elif self.lres_filter == 'gaussian':
sigma = [0, int(self.downsamp_t/2), int(self.downsamp_xz/2), int(self.downsamp_xz/2)]
output = ndimage.gaussian_filter(signal, sigma=sigma)
elif self.lres_filter == 'uniform':
output = ndimage.uniform_filter(signal, size=filter_size)
elif self.lres_filter == 'median':
output = ndimage.median_filter(signal, size=filter_size)
elif self.lres_filter == 'maximum':
output = ndimage.maximum_filter(signal, size=filter_size)
else:
raise NotImplementedError(
"lres_filter must be one of none/gaussian/uniform/median/maximum")
return output
示例7: gaussian_filter_with_nan
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import gaussian_filter [as 别名]
def gaussian_filter_with_nan(U,sigma):
"""
Apply Gaussian filter when the data contain NaN
INPUT:
U : a 2-D array (matrix)
sigma : std for the Gaussian kernel
OUTPUT:
Z : filtered matrix
"""
V=U.copy()
V[np.isnan(U)]=0
VV= ndimage.gaussian_filter(V,sigma=sigma)
W=0*U.copy()+1
W[np.isnan(U)]=0
WW= ndimage.gaussian_filter(W,sigma=sigma)
Z=VV/WW
return(Z)
#===============================================================================
#===============================================================================
示例8: test_generic_laplace01
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import gaussian_filter [as 别名]
def test_generic_laplace01(self):
def derivative2(input, axis, output, mode, cval, a, b):
sigma = [a, b / 2.0]
input = numpy.asarray(input)
order = [0] * input.ndim
order[axis] = 2
return ndimage.gaussian_filter(input, sigma, order,
output, mode, cval)
for type_ in self.types:
array = numpy.array([[3, 2, 5, 1, 4],
[5, 8, 3, 7, 1],
[5, 6, 9, 3, 5]], type_)
output = numpy.zeros(array.shape, type_)
tmp = ndimage.generic_laplace(array, derivative2,
extra_arguments=(1.0,),
extra_keywords={'b': 2.0})
ndimage.gaussian_laplace(array, 1.0, output)
assert_array_almost_equal(tmp, output)
示例9: chunk_lcn
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import gaussian_filter [as 别名]
def chunk_lcn(chunk, sigma_mean, sigma_std, std_bias=0.0, rescale=1.0):
"""
based on matlab code by Guanglei Xiong, see http://www.mathworks.com/matlabcentral/fileexchange/8303-local-normalization
assuming chunk.shape == (num_examples, x, y, channels)
'rescale' is an additional rescaling constant to get the variance of the result in the 'right' range.
"""
means = np.zeros(chunk.shape, dtype=chunk.dtype)
for k in xrange(len(chunk)):
means[k] = skimage.filter.gaussian_filter(chunk[k], sigma_mean, multichannel=True)
chunk = chunk - means # centering
del means # keep memory usage in check
variances = np.zeros(chunk.shape, dtype=chunk.dtype)
chunk_squared = chunk**2
for k in xrange(len(chunk)):
variances[k] = skimage.filter.gaussian_filter(chunk_squared[k], sigma_std, multichannel=True)
chunk = chunk / np.sqrt(variances + std_bias)
return chunk / rescale
# TODO: make this 100x faster lol. otherwise it's not usable.
示例10: get_saliency_for_shallownet
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import gaussian_filter [as 别名]
def get_saliency_for_shallownet(image_url,sal_url):
arr_files = glob.glob(image_url+"*.jpg")
for i in range(len(arr_files)):
url_image = arr_files[i]
image = io.imread(url_image)
img = misc.imresize(image,(96,96))
img = np.asarray(img, dtype = 'float32') / 255.
img = img.transpose(2,0,1).reshape(3, 96, 96)
xt = np.zeros((1, 3, 96, 96), dtype='float32')
xt[0]=img
y = juntingnet.predict(xt)
tmp = y.reshape(48,48)
blured= ndimage.gaussian_filter(tmp, sigma=3)
sal_map = cv2.resize(tmp,(image.shape[1],image.shape[0]))
sal_map -= np.min(sal_map)
sal_map /= np.max(sal_map)
#saliency = misc.imresize(y,(img.shape[0],img.shape[1]))
aux = url_image.split("/")[-1].split(".")[0]
misc.imsave(sal_url+'/'+aux+'.png', sal_map)
示例11: tf
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import gaussian_filter [as 别名]
def tf(self, img, k=0):
if self.num > 0 and k >= self.num:
return img
# image is nhwtc
for n in range(img.shape[0]):
sig = self.sigma.sample()
# sample each channel saperately to avoid correlations
if sig > self.eps:
if len(img.shape) == self.dim+2:
C = img.shape[-1]
for c in range(C):
img[n,..., c] = ndimage.gaussian_filter(img[n, ..., c], sig)
elif len(img.shape) == self.dim+1:
img[n] = ndimage.gaussian_filter(img[n], sig)
else:
raise ValueError('image shape is not supported')
return img
示例12: threshold_segmentation
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import gaussian_filter [as 别名]
def threshold_segmentation(img):
# calculate the overview level size and retrieve the image
img_hsv = img.convert('HSV')
img_hsv_np = np.array(img_hsv)
# dilate image and then threshold the image
schannel = img_hsv_np[:, :, 1]
mask = np.zeros(schannel.shape)
schannel = dilation(schannel, star(3))
schannel = ndimage.gaussian_filter(schannel, sigma=(5, 5), order=0)
threshold_global = threshold_otsu(schannel)
mask[schannel > threshold_global] = FOREGROUND
mask[schannel <= threshold_global] = BACKGROUND
return mask
示例13: circular_filter_1d
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import gaussian_filter [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
示例14: subtract_background_dog
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import gaussian_filter [as 别名]
def subtract_background_dog(z, sigma_min, sigma_max):
"""Difference of gaussians method for background removal.
Parameters
----------
sigma_max : float
Large gaussian blur sigma.
sigma_min : float
Small gaussian blur sigma.
Returns
-------
Denoised diffraction pattern as np.array
"""
blur_max = ndi.gaussian_filter(z, sigma_max)
blur_min = ndi.gaussian_filter(z, sigma_min)
return np.maximum(np.where(blur_min > blur_max, z, 0) - blur_max, 0)
示例15: find_beam_center_blur
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import gaussian_filter [as 别名]
def find_beam_center_blur(z, sigma):
"""Estimate direct beam position by blurring the image with a large
Gaussian kernel and finding the maximum.
Parameters
----------
sigma : float
Sigma value for Gaussian blurring kernel.
Returns
-------
center : np.array
np.array containing indices of estimated direct beam positon.
"""
blurred = ndi.gaussian_filter(z, sigma, mode="wrap")
center = np.unravel_index(blurred.argmax(), blurred.shape)
return np.array(center)