Following Blobs

BlitzMax Forums/BlitzMax Programming/Following Blobs

jamesmintram(Posted 2005) [#1]
Hi everyone,

I have been trying to write an algorithm that will follow and keep track of blobs on a set of images

[img]http://www.mintratech.co.uk/example.png[/img]

As you can see below over the frames the red and blue balls rotate - now I want to be able to follow those over each frame and record a position for each frame. In the program I will be using this there will only be one blob to follow of one particular colour.

Wondering if anyone can help?


Robert(Posted 2005) [#2]
I'm making a few assumptions here:

1. The blob will be a constant size, shape and colour across the frames
2. The background image is arbitrary

Grab a rectangular image of the blob, so you have a reference image to work with, then in pseudocode:

for <each frame in the image>
   for <each possible rectangle in the frame of the same size as the ref. image>
     <compare each pixel in the rect against the corresponding pixel in the reference image.  
      Assign low scores for close matches in terms of colour, and high scores when the colours do not match>

     <if the total score for this rectangle is lower than the current lowest score, then store the co-ords of this rectangle>
   next

   <Add current rect co-ords (which is the rect most closely matching the blob) to a TList>
  
next


When the loop is finished, you should have the coordinates of the part of the image that most closely resembles the blob. If the blob is circular, then you will want to assign a higher weighting on the pixels in the centre of each rectangle.
If speed is an issue then begin the scan near the location of the blob in the previous frame and stop searching when a sufficiently low score is reached.


jamesmintram(Posted 2005) [#3]
Thats great - thanks !!