Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

absdiff gives zero alpha


I am using Core.absdiff(src1, src2, dst) in OpenCV for android to compute an image difference.

Both source images originate from Android. I write both source and destination images to files, transfer to a PC, and open in Paint.Net.

The alpha channels for both source images are 255, but the alpha channel for the destination image is zero. My guess is that the absdiff is subtracting the alpha channel of both source images (255-255=0) making the alpha channel of the destination image zero – as it should.

I would like to preserve the alpha of 255. My solution is to zero the alpha channel of the src2 image before the absdiff. I'm thinking use Core.bitwise_and(src2, in2, out1) where in2 is a Scalar.

For the bitwise_and operation I'm not quite sure what values to set for the in2 scalar. Scalar(1, 1, 1, 0) seems like a good choice, but they say it's a bitwise_and. This probably would not do what I want.

Is there a better way to approach this image difference problem?

If this is a good approach, what values would I need for the four element scalar to zero the fourth channel of my second input image?

Thanks, Barry.