title: R - counting the number of objects in an image using bwlabel
body: <p>i'm rather new to image analysis in R and was wondering how i can assess the number of individual plants within a picture such as this one:
  <a href="https://i.stack.imgur.com/lQkYU.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lQkYU.jpg" alt="potato"></a></p>
  
  <p>I thought of converting the picture to a black/white picture and then using the bwlabel function to count the number of objects within the picture like this:</p>
  
  <pre><code>R&lt;-R(image)
  G&lt;-G(image)
  B&lt;-B(image)
  ExGreen&lt;-2*G-R-B
  plot(ExGreen)
  ExGreen&lt;-threshold(ExGreen,thr = "auto",approx=FALSE,adjust=1)
  
  plot(ExGreen)
  ExGreen&lt;-clean(ExGreen,10)
  plot(ExGreen)
  labels=bwlabel(ExGreen)
  max(labels)
  </code></pre>
  
  <p>However, I'm running into the issue that my white colored potato plants do not always form 1 contiguous unity.</p>
  
  <p>I was therefore wondering whether there is some option to connect the white pixels which are very close to each other or whether it is possible to draw a circle around every potato plant and then using the bwlabel function... </p>
  
  <p>Or is there any other option to solve my problem.</p>
  
  <p>Thanks in advance!</p>