here's some small changes so that now it can clearly be seen how the algorithm is working:
for each pixel in the stream, a running mean is calculated. this is only for intensity and therefore is b&w as can be seen in the background image.
for each pixel in the stream, the difference between the background and the current value is caculated. That is:
SQRT[[meanPixelValue - currentPixelValue] * [meanPixelValue - currentPixelValue]]
- a square root of a squared value ensures it's always positive
so now that we have the mean and variance, we say this (for each pixel):
Code:
Mean
|------------|------------|
< (-v * d) > < (+v * d) >
where:
v = variance
d = deviation
if the new pixel value is within the mean and its variance, then it's a background pixel so ignore. if it's outside the mean and its variance, then it's a foreground pixel so extract it.
the variance is multiplied by the deviation, so the more deviation, the more variance is allowed.
not difficult at all!