本文整理汇总了Python中scipy.ndimage.filters.maximum_filter方法的典型用法代码示例。如果您正苦于以下问题:Python filters.maximum_filter方法的具体用法?Python filters.maximum_filter怎么用?Python filters.maximum_filter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.ndimage.filters
的用法示例。
在下文中一共展示了filters.maximum_filter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: filter_local_maxima_with_std
# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import maximum_filter [as 别名]
def filter_local_maxima_with_std(self, ft2d):
data = np.abs(np.fft.fftshift(ft2d))
data /= (np.max(data) + 1e-7)
data_max = maximum_filter(data, self.neighborhood_size)
data_mean = uniform_filter(data, self.neighborhood_size)
data_mean_sq = uniform_filter(data ** 2, self.neighborhood_size)
data_std = np.sqrt(data_mean_sq - data_mean ** 2) + 1e-7
maxima = ((data_max - data_mean) / data_std)
fraction_of_local_max = (data == data_max)
maxima *= fraction_of_local_max
maxima = maxima.astype(float)
maxima /= (np.max(maxima) + 1e-7)
maxima = np.maximum(maxima, np.fliplr(maxima), np.flipud(maxima))
maxima = np.fft.ifftshift(maxima)
background_ft2d = np.multiply(maxima, ft2d)
foreground_ft2d = np.multiply(1 - maxima, ft2d)
return background_ft2d, foreground_ft2d
示例2: filter_local_maxima
# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import maximum_filter [as 别名]
def filter_local_maxima(self, ft2d):
data = np.abs(np.fft.fftshift(ft2d))
data /= (np.max(data) + 1e-7)
threshold = np.std(data)
data_max = maximum_filter(data, self.neighborhood_size)
maxima = (data == data_max)
data_min = minimum_filter(data, self.neighborhood_size)
diff = ((data_max - data_min) > threshold)
maxima[diff == 0] = 0
maxima = np.maximum(maxima, np.fliplr(maxima), np.flipud(maxima))
maxima = np.fft.ifftshift(maxima)
background_ft2d = np.multiply(maxima, ft2d)
foreground_ft2d = np.multiply(1 - maxima, ft2d)
return background_ft2d, foreground_ft2d
示例3: detect_objects_heatmap
# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import maximum_filter [as 别名]
def detect_objects_heatmap(heatmap):
data = 256 * heatmap
data_max = filters.maximum_filter(data, 3)
maxima = (data == data_max)
data_min = filters.minimum_filter(data, 3)
diff = ((data_max - data_min) > 0.3)
maxima[diff == 0] = 0
labeled, num_objects = ndimage.label(maxima)
slices = ndimage.find_objects(labeled)
objects = np.zeros((num_objects, 2), dtype=np.int32)
pidx = 0
for (dy, dx) in slices:
pos = [(dy.start + dy.stop - 1) // 2, (dx.start + dx.stop - 1) // 2]
if heatmap[pos[0], pos[1]] > config.CENTER_TR:
objects[pidx, :] = pos
pidx += 1
return objects[:pidx]
示例4: findpeaks
# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import maximum_filter [as 别名]
def findpeaks(image, thresh):
"""
Return positions of all peaks in image above threshold thresh
Based on `"detect_peaks" Stack Overflow discussion <https://stackoverflow.com/questions/3684484/peak-detection-in-a-2d-array/3689710#3689710>`_
:param image: array of values to search
:param thresh: threshold for peaks
:type image: numpy.ndarray
:type thresh: float
:returns: index array (equivalent of where output)
"""
# define an 8-connected neighborhood
neighborhood = generate_binary_structure(2,2)
# find local maximum for each pixel
amax = maximum_filter(image, footprint=neighborhood)
w = numpy.where((image == amax) & (image >= thresh))
return w
示例5: get_2D_peaks
# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import maximum_filter [as 别名]
def get_2D_peaks(arr2D, amp_min=DEFAULT_AMP_MIN):
struct = generate_binary_structure(2, 1)
neighborhood = iterate_structure(struct, PEAK_NEIGHBORHOOD_SIZE)
local_max = maximum_filter(arr2D, footprint=neighborhood) == arr2D
background = (arr2D == 0)
eroded_background = binary_erosion(background, structure=neighborhood,
border_value=1)
detected_peaks = local_max ^ eroded_background
amps = arr2D[detected_peaks]
j, i = np.where(detected_peaks)
amps = amps.flatten()
peaks = zip(i, j, amps)
peaks_filtered = [x for x in peaks if x[2] > amp_min]
frequency_idx = [x[1] for x in peaks_filtered]
time_idx = [x[0] for x in peaks_filtered]
return zip(frequency_idx, time_idx)
示例6: find_N_peaks
# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import maximum_filter [as 别名]
def find_N_peaks(signal, r=29, min_v=0.05, N=None):
max_v = maximum_filter(signal, size=r, mode='wrap')
pk_loc = np.where(max_v == signal)[0]
pk_loc = pk_loc[signal[pk_loc] > min_v]
if N is not None:
order = np.argsort(-signal[pk_loc])
pk_loc = pk_loc[order[:N]]
pk_loc = pk_loc[np.argsort(pk_loc)]
return pk_loc, signal[pk_loc]
示例7: localMax
# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import maximum_filter [as 别名]
def localMax(img, size = 5):
"""Calculates local maxima of an image
Arguments:
img (array): image
size (float or None): size of volume to search for maxima
Returns:
array: mask that is True at local maxima
"""
if size is None:
return img;
if not isinstance(size, tuple):
size = (size, size, size);
#return regmin(-img, regionalMaxStructureElement);
#return (maximum_filter(img, footprint = regionalMaxStructureElement) == img);
return (maximum_filter(img, size = size) == img)
#def regionalMax(img, regionalMaxStructureElement = numpy.ones((3,3,3), dtype = bool)):
# """Calculates regional maxima of an image."""
#
# return regmin(-img, regionalMaxStructureElement);
示例8: find_peaks
# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import maximum_filter [as 别名]
def find_peaks(param, img):
'''
Given a (grayscale) image, find local maxima whose value is above a given threshold (param['thre1'])
Args:
param (dict):
img (ndarray): Input image (2d array) where we want to find peaks
Returns:
2d np.array containing the [x,y] coordinates of each peak foun in the image
'''
peaks_binary = (maximum_filter(img, footprint=generate_binary_structure(2, 1)) == img) * (img > param['thre1'])
# Note reverse ([::-1]): we return [[x y], [x y]...] instead of [[y x], [y x]...]
return np.array(np.nonzero(peaks_binary)[::-1]).T
示例9: nms
# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import maximum_filter [as 别名]
def nms(score, ks):
assert ks % 2 == 1
ret_score = score.copy()
maxpool = maximum_filter(score, footprint=np.ones((ks, ks)))
ret_score[score < maxpool] = 0.
return ret_score
示例10: _grow
# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import maximum_filter [as 别名]
def _grow(self, arr):
return maximum_filter(arr, footprint=self._footprint)
示例11: find_N_peaks
# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import maximum_filter [as 别名]
def find_N_peaks(signal, r=29, min_v=0.05, N=None):
max_v = maximum_filter(signal, size=r, mode='wrap')
pk_loc = np.where(max_v == signal)[0]
pk_loc = pk_loc[signal[pk_loc] > min_v]
# check for odd case, remove one
if (pk_loc.shape[0]%2)!=0:
pk_id = np.argsort(-signal[pk_loc])
pk_loc = pk_loc[pk_id[:-1]]
pk_loc = np.sort(pk_loc)
if N is not None:
order = np.argsort(-signal[pk_loc])
pk_loc = pk_loc[order[:N]]
pk_loc = pk_loc[np.argsort(pk_loc)]
return pk_loc, signal[pk_loc]
示例12: find_peaks
# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import maximum_filter [as 别名]
def find_peaks(param, img):
"""
Given a (grayscale) image, find local maxima whose value is above a given
threshold (param['thre1'])
:param img: Input image (2d array) where we want to find peaks
:return: 2d np.array containing the [x,y] coordinates of each peak found
in the image
"""
peaks_binary = (maximum_filter(img, footprint=generate_binary_structure(
2, 1)) == img) * (img > param['thre1'])
# Note reverse ([::-1]): we return [[x y], [x y]...] instead of [[y x], [y
# x]...]
return np.array(np.nonzero(peaks_binary)[::-1]).T
示例13: test_all
# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import maximum_filter [as 别名]
def test_all():
print("~"*40, " maximum filter")
_test_some(max_filter, spf.maximum_filter, cval = -np.inf)
print("~" * 40, " minimum filter")
_test_some(min_filter, spf.minimum_filter, cval = np.inf)
print("~" * 40, " uniform filter")
_test_some(uniform_filter, spf.uniform_filter, cval = 0.)
示例14: r_dilation
# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import maximum_filter [as 别名]
def r_dilation(image, size, origin=0):
"""Dilation with rectangular structuring element using maximum_filter"""
return filters.maximum_filter(image, size, origin=origin)
示例15: r_erosion
# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import maximum_filter [as 别名]
def r_erosion(image, size, origin=0):
"""Erosion with rectangular structuring element using maximum_filter"""
return filters.minimum_filter(image, size, origin=origin)