Python scipy.ndimage.maximum_filter() Examples
The following are 30
code examples of scipy.ndimage.maximum_filter().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
scipy.ndimage
, or try the search function
.
Example #1
Source File: test_filters.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def test_valid_origins(): """Regression test for #1311.""" func = lambda x: np.mean(x) data = np.array([1,2,3,4,5], dtype=np.float64) assert_raises(ValueError, sndi.generic_filter, data, func, size=3, origin=2) func2 = lambda x, y: np.mean(x + y) assert_raises(ValueError, sndi.generic_filter1d, data, func, filter_size=3, origin=2) assert_raises(ValueError, sndi.percentile_filter, data, 0.2, size=3, origin=2) for filter in [sndi.uniform_filter, sndi.minimum_filter, sndi.maximum_filter, sndi.maximum_filter1d, sndi.median_filter, sndi.minimum_filter1d]: # This should work, since for size == 3, the valid range for origin is # -1 to 1. list(filter(data, 3, origin=-1)) list(filter(data, 3, origin=1)) # Just check this raises an error instead of silently accepting or # segfaulting. assert_raises(ValueError, filter, data, 3, origin=2)
Example #2
Source File: preproc.py From science_rcn with MIT License | 6 votes |
def local_nonmax_suppression(filtered, suppression_masks, num_orients=16): """ Apply oriented non-max suppression to the filters, so that only a single orientated edge is active at a pixel. See Preproc for additional parameters. Parameters ---------- filtered : numpy.ndarray Output of filtering the input image with the filter bank. Shape is (num feats, rows, columns). Returns ------- localized : numpy.ndarray Result of oriented non-max suppression. """ localized = np.zeros_like(filtered) cross_orient_max = filtered.max(0) filtered[filtered < 0] = 0 for i, (layer, suppress_mask) in enumerate(zip(filtered, suppression_masks)): competitor_maxs = maximum_filter(layer, footprint=suppress_mask, mode='nearest') localized[i] = competitor_maxs <= layer localized[cross_orient_max > filtered] = 0 return localized
Example #3
Source File: decode_multi.py From posenet-python with Apache License 2.0 | 6 votes |
def build_part_with_score_fast(score_threshold, local_max_radius, scores): parts = [] num_keypoints = scores.shape[2] lmd = 2 * local_max_radius + 1 # NOTE it seems faster to iterate over the keypoints and perform maximum_filter # on each subarray vs doing the op on the full score array with size=(lmd, lmd, 1) for keypoint_id in range(num_keypoints): kp_scores = scores[:, :, keypoint_id].copy() kp_scores[kp_scores < score_threshold] = 0. max_vals = ndi.maximum_filter(kp_scores, size=lmd, mode='constant') max_loc = np.logical_and(kp_scores == max_vals, kp_scores > 0) max_loc_idx = max_loc.nonzero() for y, x in zip(*max_loc_idx): parts.append(( scores[y, x, keypoint_id], keypoint_id, np.array((y, x)) )) return parts
Example #4
Source File: dataloader_spacetime.py From space_time_pde with MIT License | 6 votes |
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
Example #5
Source File: test_filters.py From Computable with MIT License | 6 votes |
def test_valid_origins(): """Regression test for #1311.""" func = lambda x: np.mean(x) data = np.array([1,2,3,4,5], dtype=np.float64) assert_raises(ValueError, sndi.generic_filter, data, func, size=3, origin=2) func2 = lambda x, y: np.mean(x + y) assert_raises(ValueError, sndi.generic_filter1d, data, func, filter_size=3, origin=2) assert_raises(ValueError, sndi.percentile_filter, data, 0.2, size=3, origin=2) for filter in [sndi.uniform_filter, sndi.minimum_filter, sndi.maximum_filter, sndi.maximum_filter1d, sndi.median_filter, sndi.minimum_filter1d]: # This should work, since for size == 3, the valid range for origin is # -1 to 1. list(filter(data, 3, origin=-1)) list(filter(data, 3, origin=1)) # Just check this raises an error instead of silently accepting or # segfaulting. assert_raises(ValueError, filter, data, 3, origin=2)
Example #6
Source File: mpii_demo.py From Fast_Human_Pose_Estimation_Pytorch with Apache License 2.0 | 5 votes |
def non_max_supression(plain, windowSize=3, threshold=1e-6): # clear value less than threshold under_th_indices = plain < threshold plain[under_th_indices] = 0 return plain * (plain == maximum_filter(plain, footprint=np.ones((windowSize, windowSize))))
Example #7
Source File: test_ndimage.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_maximum_filter08(self): array = numpy.array([[3, 2, 5, 1, 4], [7, 6, 9, 3, 5], [5, 8, 3, 7, 1]]) footprint = [[1, 0, 1], [1, 1, 0]] output = ndimage.maximum_filter(array, footprint=footprint, origin=-1) assert_array_almost_equal([[7, 9, 9, 5, 5], [9, 8, 9, 7, 5], [8, 8, 7, 7, 7]], output)
Example #8
Source File: test_ndimage.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_maximum_filter09(self): array = numpy.array([[3, 2, 5, 1, 4], [7, 6, 9, 3, 5], [5, 8, 3, 7, 1]]) footprint = [[1, 0, 1], [1, 1, 0]] output = ndimage.maximum_filter(array, footprint=footprint, origin=[-1, 0]) assert_array_almost_equal([[7, 7, 9, 9, 5], [7, 9, 8, 9, 7], [8, 8, 8, 7, 7]], output)
Example #9
Source File: test_filters.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_multiple_modes(): # Test that the filters with multiple mode cababilities for different # dimensions give the same result as applying a single mode. arr = np.array([[1., 0., 0.], [1., 1., 0.], [0., 0., 0.]]) mode1 = 'reflect' mode2 = ['reflect', 'reflect'] assert_equal(sndi.gaussian_filter(arr, 1, mode=mode1), sndi.gaussian_filter(arr, 1, mode=mode2)) assert_equal(sndi.prewitt(arr, mode=mode1), sndi.prewitt(arr, mode=mode2)) assert_equal(sndi.sobel(arr, mode=mode1), sndi.sobel(arr, mode=mode2)) assert_equal(sndi.laplace(arr, mode=mode1), sndi.laplace(arr, mode=mode2)) assert_equal(sndi.gaussian_laplace(arr, 1, mode=mode1), sndi.gaussian_laplace(arr, 1, mode=mode2)) assert_equal(sndi.maximum_filter(arr, size=5, mode=mode1), sndi.maximum_filter(arr, size=5, mode=mode2)) assert_equal(sndi.minimum_filter(arr, size=5, mode=mode1), sndi.minimum_filter(arr, size=5, mode=mode2)) assert_equal(sndi.gaussian_gradient_magnitude(arr, 1, mode=mode1), sndi.gaussian_gradient_magnitude(arr, 1, mode=mode2)) assert_equal(sndi.uniform_filter(arr, 5, mode=mode1), sndi.uniform_filter(arr, 5, mode=mode2))
Example #10
Source File: test_filters.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_minmax_filter(self): d = np.random.randn(500, 500) os = np.empty([4] + list(d.shape)) ot = np.empty_like(os) self.check_func_serial(4, sndi.maximum_filter, (d, 3), os) self.check_func_thread(4, sndi.maximum_filter, (d, 3), ot) assert_array_equal(os, ot) self.check_func_serial(4, sndi.minimum_filter, (d, 3), os) self.check_func_thread(4, sndi.minimum_filter, (d, 3), ot) assert_array_equal(os, ot)
Example #11
Source File: test_filters.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_footprint_all_zeros(): # regression test for gh-6876: footprint of all zeros segfaults arr = np.random.randint(0, 100, (100, 100)) kernel = np.zeros((3, 3), bool) with assert_raises(ValueError): sndi.maximum_filter(arr, footprint=kernel)
Example #12
Source File: test_ndimage.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_maximum_filter07(self): array = numpy.array([[3, 2, 5, 1, 4], [7, 6, 9, 3, 5], [5, 8, 3, 7, 1]]) footprint = [[1, 0, 1], [1, 1, 0]] output = ndimage.maximum_filter(array, footprint=footprint) assert_array_almost_equal([[3, 5, 5, 5, 4], [7, 7, 9, 9, 5], [7, 9, 8, 9, 7]], output)
Example #13
Source File: integration_generator.py From pyxem with GNU General Public License v3.0 | 5 votes |
def _get_intensities(z, vectors, radius=1): """Basic intensity integration routine, takes the maximum value at the given vector positions with the number of pixels given by `radius`. Parameters ---------- vectors : DiffractionVectors Vectors to the locations of the spots to be integrated. radius: int, Number of pixels within which to find the largest maximum Returns ------- intensities : np.array List of extracted intensities """ i, j = np.array(vectors.data).astype(int).T if radius > 1: footprint = morphology.disk(radius) filtered = ndi.maximum_filter(z, footprint=footprint) intensities = filtered[j, i].reshape(-1, 1) # note that the indices are flipped else: intensities = z[j, i].reshape(-1, 1) # note that the indices are flipped return np.array(intensities)
Example #14
Source File: post_process.py From FashionAI_KeyPoint_Detection_Challenge_Keras with MIT License | 5 votes |
def non_max_supression(plain, windowSize=3, threshold=1e-6): # clear value less than threshold under_th_indices = plain < threshold plain[under_th_indices] = 0 return plain* (plain == maximum_filter(plain, footprint=np.ones((windowSize, windowSize))))
Example #15
Source File: core.py From doatools.py with MIT License | 5 votes |
def find_peaks_simple(x): if x.ndim == 1: # Delegate to scipy's peak finder. return find_peaks(x)[0], else: # Use maximum filter for peak finding. y = maximum_filter(x, 3) return np.where(x == y)
Example #16
Source File: pose_estimator.py From Online-Realtime-Action-Recognition-based-on-OpenPose with Apache License 2.0 | 5 votes |
def non_max_suppression(plain, window_size=3, threshold=NMS_Threshold): under_threshold_indices = plain < threshold plain[under_threshold_indices] = 0 return plain * (plain == maximum_filter(plain, footprint=np.ones((window_size, window_size))))
Example #17
Source File: img.py From video-to-pose3D with MIT License | 5 votes |
def findPeak(hm): mx = maximum_filter(hm, size=5) idx = zip(*np.where((mx == hm) * (hm > 0.1))) candidate_points = [] for (y, x) in idx: candidate_points.append([x, y, hm[y][x]]) if len(candidate_points) == 0: return torch.zeros(0) candidate_points = np.array(candidate_points) candidate_points = candidate_points[np.lexsort(-candidate_points.T)] return torch.Tensor(candidate_points)
Example #18
Source File: test_ndimage.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_maximum_filter05(self): array = numpy.array([[3, 2, 5, 1, 4], [7, 6, 9, 3, 5], [5, 8, 3, 7, 1]]) filter_shape = numpy.array([2, 3]) output = ndimage.maximum_filter(array, filter_shape) assert_array_almost_equal([[3, 5, 5, 5, 4], [7, 9, 9, 9, 5], [8, 9, 9, 9, 7]], output)
Example #19
Source File: test_ndimage.py From Computable with MIT License | 5 votes |
def test_maximum_filter01(self): array = numpy.array([1, 2, 3, 4, 5]) filter_shape = numpy.array([2]) output = ndimage.maximum_filter(array, filter_shape) assert_array_almost_equal([1, 2, 3, 4, 5], output)
Example #20
Source File: test_ndimage.py From Computable with MIT License | 5 votes |
def test_maximum_filter02(self): array = numpy.array([1, 2, 3, 4, 5]) filter_shape = numpy.array([3]) output = ndimage.maximum_filter(array, filter_shape) assert_array_almost_equal([2, 3, 4, 5, 5], output)
Example #21
Source File: test_ndimage.py From Computable with MIT License | 5 votes |
def test_maximum_filter03(self): array = numpy.array([3, 2, 5, 1, 4]) filter_shape = numpy.array([2]) output = ndimage.maximum_filter(array, filter_shape) assert_array_almost_equal([3, 3, 5, 5, 4], output)
Example #22
Source File: test_ndimage.py From Computable with MIT License | 5 votes |
def test_maximum_filter04(self): array = numpy.array([3, 2, 5, 1, 4]) filter_shape = numpy.array([3]) output = ndimage.maximum_filter(array, filter_shape) assert_array_almost_equal([3, 5, 5, 5, 4], output)
Example #23
Source File: test_ndimage.py From Computable with MIT License | 5 votes |
def test_maximum_filter05(self): array = numpy.array([[3, 2, 5, 1, 4], [7, 6, 9, 3, 5], [5, 8, 3, 7, 1]]) filter_shape = numpy.array([2, 3]) output = ndimage.maximum_filter(array, filter_shape) assert_array_almost_equal([[3, 5, 5, 5, 4], [7, 9, 9, 9, 5], [8, 9, 9, 9, 7]], output)
Example #24
Source File: test_ndimage.py From Computable with MIT License | 5 votes |
def test_maximum_filter07(self): array = numpy.array([[3, 2, 5, 1, 4], [7, 6, 9, 3, 5], [5, 8, 3, 7, 1]]) footprint = [[1, 0, 1], [1, 1, 0]] output = ndimage.maximum_filter(array, footprint=footprint) assert_array_almost_equal([[3, 5, 5, 5, 4], [7, 7, 9, 9, 5], [7, 9, 8, 9, 7]], output)
Example #25
Source File: test_ndimage.py From Computable with MIT License | 5 votes |
def test_maximum_filter08(self): array = numpy.array([[3, 2, 5, 1, 4], [7, 6, 9, 3, 5], [5, 8, 3, 7, 1]]) footprint = [[1, 0, 1], [1, 1, 0]] output = ndimage.maximum_filter(array, footprint=footprint, origin=-1) assert_array_almost_equal([[7, 9, 9, 5, 5], [9, 8, 9, 7, 5], [8, 8, 7, 7, 7]], output)
Example #26
Source File: test_ndimage.py From Computable with MIT License | 5 votes |
def test_maximum_filter09(self): array = numpy.array([[3, 2, 5, 1, 4], [7, 6, 9, 3, 5], [5, 8, 3, 7, 1]]) footprint = [[1, 0, 1], [1, 1, 0]] output = ndimage.maximum_filter(array, footprint=footprint, origin=[-1, 0]) assert_array_almost_equal([[7, 7, 9, 9, 5], [7, 9, 8, 9, 7], [8, 8, 8, 7, 7]], output)
Example #27
Source File: lib.py From sea_ice_drift with GNU General Public License v3.0 | 5 votes |
def get_invalid_mask(img, n, landmask_border): """ Create mask of invalid pixels (land, cosatal, inf) Parameters ---------- img : float ndarray input image n : Nansat input Nansat object landmask_border : int border around landmask Returns ------- mask : 2D bool ndarray True where pixels are invalid """ mask = np.isnan(img) + np.isinf(img) n.resize(1./landmask_border) try: wm = n.watermask()[1] except: print('Cannot add landmask') else: wm[wm > 2] = 2 wmf = maximum_filter(wm, 3) wmz = zoom(wmf, (np.array(img.shape) / np.array(wm.shape))) mask[wmz == 2] = True n.undo() return mask
Example #28
Source File: test_ndimage.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_maximum_filter01(self): array = numpy.array([1, 2, 3, 4, 5]) filter_shape = numpy.array([2]) output = ndimage.maximum_filter(array, filter_shape) assert_array_almost_equal([1, 2, 3, 4, 5], output)
Example #29
Source File: test_ndimage.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_maximum_filter02(self): array = numpy.array([1, 2, 3, 4, 5]) filter_shape = numpy.array([3]) output = ndimage.maximum_filter(array, filter_shape) assert_array_almost_equal([2, 3, 4, 5, 5], output)
Example #30
Source File: test_ndimage.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_maximum_filter03(self): array = numpy.array([3, 2, 5, 1, 4]) filter_shape = numpy.array([2]) output = ndimage.maximum_filter(array, filter_shape) assert_array_almost_equal([3, 3, 5, 5, 4], output)