OpenCV is an image processing library created by intel which includes various packages and several functions in it. OpenCV is used to solve many problems in computer vision and machine learning applications and due to its large community, it is getting updated day by day. OpenCV can be implemented in C++, Python, Java programming languages, and different platforms like Linux, Windows, macOS.

In this article, we will demonstrate one of the interesting applications of OpenCV in performing bitwise operations on images.

Topics covered in this article

  • Bitwise Operators in Computer Vision
  • Bitwise AND
  • Bitwise OR
  • Bitwise NOT
  • Bitwise XOR

Bitwise Operators in Computer Vision

Bitwise operations can be used in image manipulations. These bitwise techniques are used in many computer vision applications like for creating masks of the image, adding watermarks to the image and it is possible to create a new image using these bitwise operators. These operations work on the individual pixels in the image to give accurate results compared with other morphing techniques in OpenCV.


Using the below code snippet, we will create two images – image1, image2 as input images on which the bitwise operations will be performed.

import numpy as np

import cv2

from google.colab.patches import cv2_imshow

image1 = np.zeros((400, 400), dtype="uint8")

cv2.rectangle(image1, (100, 100), (250, 250), 255, -1)

cv2_imshow(image1)

image2 = np.zeros((400, 400), dtype="uint8")

cv2.circle(image2, (150, 150), 90, 255, -1)

cv2_imshow(image2)


#developers corner #bitwise and #bitwise not #bitwise or #bitwise xor #opencv image processing

How to Implement Bitwise Operations On Images Using OpenCV?
2.75 GEEK