Merge pull request #249 from ahojnnes/peak-local-max

BUG: Fix num_peaks parameter bug in peak_local_max.
This commit is contained in:
Stefan van der Walt
2012-08-15 00:53:41 -07:00
2 changed files with 13 additions and 5 deletions
+3 -3
View File
@@ -95,9 +95,9 @@ def peak_local_max(image, min_distance=10, threshold='deprecated',
# get coordinates of peaks
coordinates = np.transpose(image_t.nonzero())
if len(coordinates) > num_peaks:
intensities = image[tuple(coordinates.T)]
if coordinates.shape[0] > num_peaks:
intensities = image[coordinates[:, 0], coordinates[:, 1]]
idx_maxsort = np.argsort(intensities)[::-1]
coordinates = coordinates[idx_maxsort][:2]
coordinates = coordinates[idx_maxsort][:num_peaks]
return coordinates
+10 -2
View File
@@ -51,15 +51,23 @@ def test_flat_peak():
def test_num_peaks():
image = np.zeros((3, 7), dtype=np.uint8)
image = np.zeros((7, 7), dtype=np.uint8)
image[1, 1] = 10
image[1, 3] = 11
image[1, 5] = 12
assert len(peak.peak_local_max(image, min_distance=1)) == 3
image[3, 5] = 8
image[5, 3] = 7
assert len(peak.peak_local_max(image, min_distance=1)) == 5
peaks_limited = peak.peak_local_max(image, min_distance=1, num_peaks=2)
assert len(peaks_limited) == 2
assert (1, 3) in peaks_limited
assert (1, 5) in peaks_limited
peaks_limited = peak.peak_local_max(image, min_distance=1, num_peaks=4)
assert len(peaks_limited) == 4
assert (1, 3) in peaks_limited
assert (1, 5) in peaks_limited
assert (1, 1) in peaks_limited
assert (3, 5) in peaks_limited
if __name__ == '__main__':