Search code examples
c++opencvimage-processingcomputer-visionimagefilter

Subtracting two images in Computer Vision


I have been working on computer vision and openCV (C++) I applied a filter

[0,0,0,0,0,1,0,0,0]

on an image and got the result image_result.

I took the difference :

image_result - image.

But I found a couple of programs where the subtraction is done this way:

    image_result - image + image - image_result

Can someone give me an idea why the subtraction is done in the above mentioned way and Is it the right way to find the difference between two images?

Thank you


Solution

  • I guess this is specifically for unsigned pixels and using saturation arithmetic, where subtraction that leads to a negative number yields 0 instead. The first subtraction gives you the values where the result is larger, the second one where the result is smaller. The result would be equivalent to abs(image-image_result) if using normal, signed arithmetic.