title: Algorithm to find peaks in 2D array
body: <p>Let's say I have a 2D accumulator array in java <code>int[][] array</code>. The array could look like this: </p>
  
  <p>(x and z axes represent indexes in the array, y axis represents values - these are images of an <code>int[56][56]</code> with values from 0 ~ 4500)
  <img src="https://i.stack.imgur.com/FOsfU.png" alt="array sample 1"></p>
  
  <p>or</p>
  
  <p><img src="https://i.stack.imgur.com/Cpaeq.png" alt="array sample 1"></p>
  
  <p><strong>What I need to do is find peaks in the array</strong> - there are 2 peaks in the first one and 8 peaks in the second array. These peaks are always 'obvious' (there's always a gap between peaks), but they don't have to be similar like on these images, they can be more or less random - these images are not based on the real data, just samples. The real array can have size like 5000x5000 with peaks from thousands to several hundred thousands... The algorithm has to be universal, I don't know how big the array or peaks can be, I also don't know how many peaks there are. But I do know some sort of threshold - that the peaks can't be smaller than a given value.</p>
  
  <p>The problem is, that one peak can consist of several smaller peaks nearby (first image), the height can be quite random and also the size can be significantly different within one array (size - I mean the number of units it takes in the array - one peak can consist from 6 units and other from 90). It also has to be fast (all done in 1 iteration), the array can be really big.</p>
  
  <p>Any help is appreciated - I don't expect code from you, just the right idea :) Thanks!</p>
  
  <p><hr>
  <strong>edit:</strong> You asked about the domain - but it's quite complicated and imho it can't help with the problem. It's actually an array of ArrayLists with 3D points, like ArrayList&lt; Point3D >[][] and the value in question is the size of the ArrayList. Each peak contains points that belong to one cluster (plane, in this case) - this array is a result of an algorithm, that segments a pointcloud . I need to find the highest value in the peak so I can fit the points from the 'biggest' arraylist to a plane, compute some parameters from it and than properly cluster most of the points from the peak.</p>