Last active
November 5, 2015 18:38
-
-
Save mdauphin/71637b067479d3d3ed89 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def LocalMaximaFinder( im, kernel = [ 32, 32 ], threshold = 0, min_distance = 0 ): | |
( h, w ) = im.shape | |
results = [] | |
for y in range(0,h,kernel[0]): | |
for x in range(0,w,kernel[1]): | |
sub = im[y:y+kernel[0],x:x+kernel[1]] | |
max_pxl_value = np.max(sub) | |
if max_pxl_value > threshold: | |
max_pos = np.array(np.unravel_index(np.argmax(sub),sub.shape)) + [y,x] | |
#distance | |
if len(results) > 0: | |
all_pos = np.array([ x[1] for x in results ]) | |
print np.min( np.linalg.norm( all_pos - max_pos, axis=1 ) ) | |
if np.min( np.linalg.norm( all_pos - max_pos, axis=1 ) ) > min_distance: | |
results.append( (max_pxl_value, tuple(max_pos)) ) | |
else: | |
results.append( (max_pxl_value, tuple(max_pos)) ) | |
#sort | |
results = sorted( results, key=lambda x: x[0], reverse=True ) | |
return [ x[1] for x in results ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment