views:

900

answers:

1

I am using EmguCV and am trying to subtract 2 images to create a filter similar to AForge .NET's MoveTowards filter.

This is what my slightly modified version from the above URL tries to do. Given 2 images, the source and the overlay - it slowly moves the source image towards the overlay. It does this based on the following:

result = source + movementFactor * (overlay - source);

where result, source and overlay are images and movementFactor is the rate of change in the range 0 to 1.

When I tried this in code with movementFactor equal to 1, the results looked messed up (there was something like a motion trail). To test it further, I removed movementFactor from the above equation, and made result = source + overlay - source. I expected to see the overlay image as the result, which I did, but along with one region of the image that was flashing.

I am guessing that pixel intensities get clipped in the upper or lower bounds when addition/subtraction takes place.

I can accomplish what I want with this:

for (int i = 0; i < src.Height; i++)
{
    for (int j = 0; j < src.Width; j++)
    {
        res[i, j] = new Gray(src[i, j].Intensity + movementFactor * (ovr[i, j].Intensity - src[i, j].Intensity));
    }
}

But this significantly slows down the processing. How can I overcome the addition/subtraction problem or the speed problem with the above? Thanks for your answers!

A: 

I will post the answer I found over here, in case someone runs across the same issue in the future.

This is how you would do it:

Image<Gray,Byte> result = new Image<Gray,Byte>(source.Size);
CvInvoke.cvAddWeighted(source, 1.0-movementFactor, overlay, movementFactor, 0.0, result);

Source: EmguCV's forums, here is the post that gave me the reply

aip.cd.aish