pix_colortrack

click here to DOWNLOAD the source and a help patch.

Information:

This object for Pd/GEM is somewhat abandoned, but the principle with which it works is better than most color tracking algorithms when one wants to track pure colors, that is, the corners of an RGB cube space.

After several experiments with saturation, brightness, contrast and other tests, I discovered that the pixels that correctly tracked the color, were perfectly described by a plane such as the one in the RGB space image beside, leaving the top corner as our objective to track. Instead of this piramid, most video trackers look for a cube on the top red corner, allowing for pixels that are closer to grey than to red.
.
This plane is a 2-dimensional subspace of the 3-dimensional RGB space. To describe it correctly we use three RGB vectors that span it. For example, let’s use these: (0.6 0 0), (1 0.8 0) and (1 0 0.5) and use them as rows of a matrix.
.
0.60 0.00 0.00
1.00 0.80 0.00
1.00 0.00 0.50
.
Since subspaces have to cross the origin, we substract 0.5 (what we will call the red offset) from the red values of the pixels to shift the plane to go through the origin. This leaves us with the vectors (0 0 0), (0.5 0.7 0) and (0.5 0 0.6) and the new matrix:
.
0.40 0.80 0.00
0.40 0.00 0.50
.
Elimination of this matrix leaves us with:
.
0.40 0.80 0.00
0.00 -0.80 0.50
.
Now we can describe the nullspace for this plane:
.
– 1/(1-0.6) * R + 1/0.8 * G + 1/0.5 * B = 0
.
This is the equation for the nullspace of this plane, that is, all RGB sets that when substituted in this equation produce zero. Therefore, all pixels that do not lie on the plane will produce either a positive or negative value, identifiing in that way which ones are above or below the plane.
.
After identifying these pixels, the object makes a histogram of them in both axis of the image and determines the coordinates of the tracked object by finding the median.
.
Because of it’s original intention, that of tracking two mallets the object right now only has red and blue options, but it should be fairly easy to provide other pure colors.
.

Leave a Reply

Your email address will not be published. Required fields are marked *