本文整理汇总了Python中scipy.ndimage.filters.median_filter方法的典型用法代码示例。如果您正苦于以下问题:Python filters.median_filter方法的具体用法?Python filters.median_filter怎么用?Python filters.median_filter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.ndimage.filters
的用法示例。
在下文中一共展示了filters.median_filter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: smooth_magseries_ndimage_medfilt
# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import median_filter [as 别名]
def smooth_magseries_ndimage_medfilt(mags, windowsize):
'''This smooths the magseries with a median filter that reflects the array
at the boundary.
See https://docs.scipy.org/doc/scipy/reference/tutorial/ndimage.html for
details.
Parameters
----------
mags : np.array
The input mags/flux time-series to smooth.
windowsize : int
This is a odd integer containing the smoothing window size.
Returns
-------
np.array
The smoothed mag/flux time-series array.
'''
return median_filter(mags, size=windowsize, mode='reflect')
示例2: pick_peaks
# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import median_filter [as 别名]
def pick_peaks(nc, L=16, offset_denom=0.1):
"""Obtain peaks from a novelty curve using an adaptive threshold."""
offset = nc.mean() * float(offset_denom)
th = filters.median_filter(nc, size=L) + offset
#th = filters.gaussian_filter(nc, sigma=L/2., mode="nearest") + offset
#import pylab as plt
#plt.plot(nc)
#plt.plot(th)
#plt.show()
# th = np.ones(nc.shape[0]) * nc.mean() - 0.08
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)
return peaks
示例3: pick_peaks
# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import median_filter [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
示例4: filter_activation_matrix
# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import median_filter [as 别名]
def filter_activation_matrix(G, R):
"""Filters the activation matrix G, and returns a flattened copy."""
#import pylab as plt
#plt.imshow(G, interpolation="nearest", aspect="auto")
#plt.show()
idx = np.argmax(G, axis=1)
max_idx = np.arange(G.shape[0])
max_idx = (max_idx, idx.flatten())
G[:, :] = 0
G[max_idx] = idx + 1
# TODO: Order matters?
G = np.sum(G, axis=1)
G = median_filter(G[:, np.newaxis], R)
return G.flatten()
示例5: set_prefilter
# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import median_filter [as 别名]
def set_prefilter(self,gaussian = False, median = False, params = []):
self._do_prefilter_data = False
if gaussian or median:
self._do_prefilter_data = True
#print gaussian, median
if median:
self._prefilter = median_filter
#print("median_filter")
if params:
self._prefilter_params = params[0]
else:
self._prefilter_params = 6
if gaussian:
self._prefilter = gaussian_filter1d
#print("gaussian_filter1d")
if params:
self._prefilter_params = params[0]
else:
self._prefilter_params = 6 # 0.4
示例6: _smooth_raster
# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import median_filter [as 别名]
def _smooth_raster(self, raster, ws, resolution, circular=False):
""" Smooth a raster with a median filter
Parameters
----------
raster : ndarray
raster to be smoothed
ws : int
window size of smoothing filter
resolution : int
resolution of raster in m
circular : bool, optional
set to True for disc-shaped filter kernel, block otherwise
Returns
-------
ndarray
smoothed raster
"""
return filters.median_filter(
raster, footprint=self._get_kernel(ws, circular=circular))
示例7: filter
# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import median_filter [as 别名]
def filter(self, cov, *args, **kwargs):
cdim = cov.shape
npol = cdim[0] // 2
c_int = lambda n: cov[n, n, ...].real
max_coh = np.zeros(cdim[2:], dtype='f8')
inten = np.zeros(cdim[2:], dtype='f8')
for n in range(npol):
coh = np.abs(cov[n, n + npol, ...]) / np.sqrt(c_int(n) * c_int(n + npol))
up_mask = (coh > max_coh)
max_coh = (1 - up_mask) * max_coh + up_mask * coh
inten = (1 - up_mask) * inten + 0.5 * up_mask * (c_int(n) + c_int(n + npol))
mask = np.asarray((inten > self.noise) * (max_coh < self.coh_thresh), dtype='u1')
return median_filter(mask, 3, mode='constant', cval=0)
示例8: median_filter
# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import median_filter [as 别名]
def median_filter(X, M=8):
"""Median filter along the first axis of the feature matrix X."""
for i in range(X.shape[1]):
X[:, i] = filters.median_filter(X[:, i], size=M)
return X
示例9: _test_single
# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import median_filter [as 别名]
def _test_single(dshape, size , cval = 0., dtype = np.float32, skip_assert = False):
d = np.random.randint(0, 40, dshape).astype(dtype)*0
out1 = spf.median_filter(d, size, mode = "constant", cval = cval)
out2 = median_filter(d, size, cval=cval)
print(("shape: %s \tsize: %s\tcval: %.2f\tdtype: %s\tdifference: %.2f" % (dshape, size,cval, dtype,np.amax(np.abs(out1 - out2)))))
if not skip_assert:
npt.assert_almost_equal(out1,out2, decimal = 5)
return out1, out2
示例10: median_filter_all_colours
# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import median_filter [as 别名]
def median_filter_all_colours(im_small, window_size):
"""
Applies a median filer to all colour channels
"""
ims = []
for d in range(3):
im_conv_d = median_filter(im_small[:,:,d], size=(window_size,window_size))
ims.append(im_conv_d)
im_conv = np.stack(ims, axis=2).astype("uint8")
return im_conv
示例11: compare_pyfunc_median_filter_with_direct_call
# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import median_filter [as 别名]
def compare_pyfunc_median_filter_with_direct_call(self):
with self.test_session() as sess:
test_input = np.random.random((10, 9)).astype(np.float32)
test_kernel = (3, 3)
test_input_tf = tf.convert_to_tensor(test_input)
filter_result_tf = grasp_dataset_median_filter(test_input_tf, test_kernel[0], test_kernel[1])
filter_result_np = median_filter(test_input, test_kernel)
filter_result_tf = sess.run(filter_result_tf)
self.assertAllEqual(filter_result_tf, filter_result_np)
示例12: compute_snr
# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import median_filter [as 别名]
def compute_snr(power_2d, fractional_window_size=0.05):
"""
Extract the central region of the 2D Fourier transform
Parameters
----------
power_2d : numpy array
The 2D Fourier transform of the data
fractional_window_size : float
Median filter window size as a fraction of the 1D power array
Returns
-------
snr : numpy array
The 1D SNR
"""
power = np.median(power_2d, axis=0)
p2p_scatter = abs(power[1:] - power[:-1])
power = power[1:] # Throw away DC term
# Median filter
window_size = get_odd_integer(fractional_window_size * len(power))
continuum = median_filter(power, size=window_size)
pixel_to_pixel_scatter = median_filter(p2p_scatter, size=window_size)
snr = (power - continuum) / pixel_to_pixel_scatter
# Also divide out the global scatter for any residual structure that was not removed with the median filter
global_scatter = robust_standard_deviation(snr)
snr /= global_scatter
return snr
示例13: deprocess_img_and_save
# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import median_filter [as 别名]
def deprocess_img_and_save(img, filename):
"""Undo pre-processing on an image, and save it."""
img = img[0, :, :, :]
add_imagenet_mean(img)
img = img[::-1].transpose((1, 2, 0))
img = np.clip(img, 0, 255).astype(np.uint8)
img = median_filter(img, size=(3, 3, 1))
try:
imsave(filename, img)
except OSError as e:
print(e)
sys.exit(1)
示例14: __call__
# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import median_filter [as 别名]
def __call__(self, data, num_semg_row, num_semg_col, **kargs):
return np.array([median_filter(image, 3).ravel() for image
in data.reshape(-1, num_semg_row, num_semg_col)])
示例15: _csl_cut
# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import median_filter [as 别名]
def _csl_cut(data, framerate):
window = int(np.round(150 * framerate / 2048))
data = data[:len(data) // window * window].reshape(-1, 150, data.shape[1])
rms = np.sqrt(np.mean(np.square(data), axis=1))
rms = [median_filter(image, 3).ravel() for image in rms.reshape(-1, 24, 7)]
rms = np.mean(rms, axis=1)
threshold = np.mean(rms)
mask = rms > threshold
for i in range(1, len(mask) - 1):
if not mask[i] and mask[i - 1] and mask[i + 1]:
mask[i] = True
from .. import utils
begin, end = max(utils.continuous_segments(mask),
key=lambda s: (mask[s[0]], s[1] - s[0]))
return begin * window, end * window