It's convenient to represent binary images—images containing only black and white pixels—using np.uint8 arrays with only 0 and 255 values correspondingly. Both OpenCV and NumPy support all usual binary operators: NOT, AND, OR, and XOR. They are available through aliases, such as ~, &, |, ^, as well as through functions such as cv2.bitwise_not/np.bitwise_not and cv2.bitwise_and/np.bitwise_and.
After running the preceding code, the following output is expected: