tags:

views:

110

answers:

1

Is there a simple way to invert a mask using OpenCV? For example, if I've got a mask like this:

010
111
010

I'd like to invert it and get this:

101
000
101

Note: I'm using OpenCV's Python bindings, so while it would be possible to simply loop over each element in the mask, execution speed could become an issue.

+1  A: 

Use a bitwise Not to flip all bits in a matrix.

Ian Wetherbee
It's possible that I'm doing something stupid and wrong, but I don't think a bitwite-not is what I want… Because then I'll end up with `255,254,255,...`. Possibly it's because my mask is an `Image`?
David Wolever
It depends upon the bit depth of your mask. Normally a mask should have a depth of 1 bit, which would flip the single bit from 0 to 1 and vise versa. You might need to convert your mask to a 1 bit deep image first.If you have a greater bit depth (ex 4), then yes it would flip from `0001` to `1110` and from `0000` to `1111`
Ian Wetherbee