Search⌘ K

Bitwise Operations

Explore how bitwise operators such as AND, OR, XOR, and NOT work in OpenCV to combine and manipulate images. This lesson helps you understand using these operators to edit black and white images, create masks, and apply complex image blends with practical Python examples.

Instead of just stacking images, we might also want to combine images. We’ll use bitwise operators to combine images in OpenCV. In this lesson, we’ll work with black in white images to better understand these operators.

What are bitwise operators?

There are four basic bitwise operatorsAND, OR, XOR, and NOT. These operators are frequently used to edit images, especially while working with masking images.

First, we’ll create a blank image.

To create a blank image, we use the np.zeros() function of the OpenCV library.

blank = np.zeros((600,600), dtype='uint8')

Note: We must import the NumPy library to use this function.

This function requires two parameters. The first parameter is the size of the blank image and the second parameter, ...