title: Identify groups of similar-coloured pixels
body: <p>I am writing some software that periodically checks a camera image to identify whether an object has been introduced to the viewed scene. I am using <a href="http://www.imagemagick.org/script/index.php" rel="nofollow noreferrer">ImageMagick</a> in my WinForms software to compare two images to create a third. In the third image, a pixel is white if the first two images had a similar-coloured pixel, and black if they were different. So if the user sees a group of black pixels, they will know something has been placed in the scene that wasn't there previously, as seen here:
  <a href="https://i.stack.imgur.com/FcaYZ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FcaYZ.jpg" alt="enter image description here"></a></p>
  
  <p>The user will not be seeing this image, so I would like my software to identify this for me. I don't need anything too complex from this analysis - just a Boolean for whether something was changed in the scene.</p>
  
  <p>In my mind, there are two approaches to analysing this; counting the number of black pixels in the image, or I could write some algorithm to identify patches of black. My question is about the second approach, since it feels like the more correct approach. The image is a bit too noisy (you can see false positives on straight edges) for me to feel entirely comfortable with counting.</p>
  
  <p>To identify a group, I have considered using some for loops to look at the colours of pixels surrounding every pixel but this seems like it would take forever. My processing time can't take more than a few seconds so I need to be wary of this. Are there cleaner or more-efficient ways to identify groups of similarly-coloured pixels? Or will I need to run loops and be as efficient as possible?</p>