title: Finding two major peaks and the valleys between the peaks of a 2D array or histogram
body: <pre><code>for (int i = 0; i &lt; c.length; i++)
  {
      for(int j=0; j&lt;c[i].length;j++)
      {
           if(peak1[i]&lt;c[i][j]){
           peak1[i] = c[i][j];
           peak1loc1[i]= j;
       }
  }     
  
  
   println(peak1[2]);
   println(peak2[2]);`
  </code></pre>
  
  <p>Here is what I have tried so far. For some reason <code>peak1</code> and <code>peak2</code> are printing the same values.</p>
  
  <p>I have a 2-dimensional array that holds RGB color values of an image. I want to find two major peaks of each channel (r,g,b), and the valley between these two major peaks, so I will get two major peaks for red, two major peaks for green, two major peaks for blue and a valley (the smallest value between the major peaks), so three valleys in total.</p>
  
  <p>Is there any algorithm for this or can anyone give me some ideas how I can find these? A pseudocode would be really helpful.</p>