I visited the link https://stackoverflow.com/questions/3684484/peak-detection-in-a-2d-array/3689710#3689710 and use the following script
#NOTE: I get the code from the link above from scipy import * from operator import itemgetter n = 3 # how many fingers are we looking for #d = loadtxt("paw.txt") #data = [DATA of a 2d array] width, height = data.shape # Create an array where every element is a sum of 2x2 squares. fourSums = data[:-1,:-1] + data[1:,:-1] + data[1:,1:] + data[:-1,1:] # Find positions of the fingers. # Pair each sum with its position number (from 0 to width*height-1), pairs = zip(arange(width*height), fourSums.flatten()) # Sort by descending sum value, filter overlapping squares def drop_overlapping(pairs): no_overlaps =  def does_not_overlap(p1, p2): i1, i2 = p1, p2 r1, col1 = i1 / (width-1), i1 % (width-1) r2, col2 = i2 / (width-1), i2 % (width-1) return (max(abs(r1-r2),abs(col1-col2)) >= 2) for p in pairs: if all(map(lambda prev: does_not_overlap(p,prev), no_overlaps)): no_overlaps.append(p) return no_overlaps pairs2 = drop_overlapping(sorted(pairs, key=itemgetter(1), reverse=True)) # Take the first n with the heighest values positions = pairs2[:n] # Print results print(data, "\n") for i, val in positions: row = i // (width-1) column = i % (width-1) print("sum = %f @ %d,%d (%d)" % (val, row, column, i)) print(data[row:row+2,column:column+2])
The above script provides 2 adjacent matrix[2*2] of the same peaks.
## 01: Local matrix of the peak sum = 0.002482 @ 128,190 (65342) [[0.0006202 0.00062187] [0.00061926 0.00062093]] ## 02: Local matrix of the peak sum = 0.002479 @ 128,191 (65343) [[0.00062187 0.0006184 ] [0.00062093 0.00061746]]
Also, I've tried with varying 'n' and no. of rows and columns but it gives me different local matrix for the same peak (probably I missed something) which does not match with my expectation. I want to find local peaks or a number of local maxima as shown in fig. 01 and Fig. 02. How can I get the local maxima efficiently? Can anybody help me in this regard?