title: Detecting peaks in images
body: <p>I got a large set of infrared images of seeds, their sizes vary slightly.
  And I would like to find them (in thefastest possible way).
  Below i show zoomed in details of the images i process.
  After a first noise removal and blob filter this is what i have :
  <a href="https://i.stack.imgur.com/Qc91J.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Qc91J.png" alt="enter image description here"></a></p>
  
  <p>The bright white is just direct reflection of the IR lamp, white pixels never combine (stretch out) over multiple seeds.</p>
  
  <p>To make it more clear i placed a letter on some individual seeds.
  <a href="https://i.stack.imgur.com/WpQ8a.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WpQ8a.png" alt="enter image description here"></a></p>
  
  <p>The problems i have:</p>
  
  <ul>
  <li>A is a single seed (dirt on the seed) generates a slight dark line.</li>
  <li>B the nearby X close to it is at its darkest intersection its still brighter as some other seeds (cannt change brightnes or remove if gray value is lower then a certain value.</li>
  <li>C those are 3 seeds close to each other.</li>
  <li>The smallest visible seeds above should not becomme even smaller.</li>
  </ul>
  
  <p>I'm not making use of mathlab or openCV, as i work directly with locked image and memory data. i can acces pixel data by array or simple getpixel / putpixel commands. I wrote my own graphics library which is fast enough for live camera data, processing speed currently at around 13ms at around 25ms i enter stream processing lag </p>
  
  <p>I wonder how to separate those 'cloudy' blobs better.
  I'm thinking to find local maxima over a certain pixels range..but that should see A as one seed, while on B find that B and X are not connected.
  So I'm not sure here, how such a local peek function or another function should like like. Although i code in C# i looked at other c++ functions as well like dilate etc but thats not it. I also wrote a function to check for slope degree (like if it was a mountain height image) but that couldnt devide areas B and C.</p>
  
  <p>Ok well i made different slope detection code, now i dont look for some degree but just the tilting point over a small range, it works nice on X axis.. but essentially i think it should work on both X and Y
  here's the new result :
  <a href="https://i.stack.imgur.com/YatWX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YatWX.png" alt="enter image description here"></a>
  It can resolve issue A and B  !!!</p>
  
  <p>However it wouldnt differentiate between seeds who are aligned in a vertical row, and and it causes small white noise (non connected lines). at places where is there is nearly nothing to detect. I'm not yet sure on how to do the same (combined) over Y axis to get the tops then erase stuff from a certain distance of the top.. (to seperate).</p>
  
  <p>Using this code just showing the pixel operations of it.</p>
  
  <pre><code> for (int y =  raw.Height;y&gt;5; y--)
          {slopeUP = false;
              int[] peek = new int[raw.Width];
              for (int x = raw.Width; x&gt; 7; x--)
              {
                  int a = raw.GetPixelBleu(x, y);
                  int b = raw.GetPixelBleu(x - 1, y);
                  int c = raw.GetPixelBleu(x - 2, y);
                  int d = raw.GetPixelBleu(x - 11, y);
                  int f = raw.GetPixelBleu(x - 12, y);
  
                  if ((f + d) &gt; (a + b))slopeUP  = true;
  
                  if ((f + d) &lt; (a + b))
                  {
                      if (slopeUP)
                      {
                          slopeUP = false;
                          peek[x - 6] = 10;
                          //raw.SetPixel(x, y, Color.GreenYellow);
                      }
                      else peek[x - 6] = 0;
                  }
  
              }
              for (int x = raw.Width; x &gt; 7; x--) 
              { if (peek[x-1] &gt; 5) raw.SetPixel(x, y, Color.Lavender); }
       }
  </code></pre>