VOOZH about

URL: https://www.geeksforgeeks.org/python/arithmetic-operations-on-images-using-opencv-set-2-bitwise-operations-on-binary-images/

⇱ Bitwise Operations on Binary Images in OpenCV2 - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Bitwise Operations on Binary Images in OpenCV2

Last Updated : 12 Apr, 2025

Bitwise operations are used in image manipulation and used for extracting essential parts in the image. In this article, Bitwise operations used are :

  1. AND
  2. OR
  3. XOR
  4. NOT

Also, Bitwise operations helps in image masking. Image creation can be enabled with the help of these operations. These operations can be helpful in enhancing the properties of the input images. 

NOTE: The Bitwise operations should be applied on input images of same dimensions.

Input Image 1:

👁 Image

Input Image 2: 

👁 Image

Bitwise AND operation on Image:

Bit-wise conjunction of input array elements. 

Syntax: cv2.bitwise_and(source1, source2, destination, mask)
Parameters:
source1: First Input Image array(Single-channel, 8-bit or floating-point) 
source2: Second Input Image array(Single-channel, 8-bit or floating-point) 
dest: Output array (Similar to the dimensions and type of Input image array) 
mask: Operation mask, Input / output 8-bit single-channel mask 

Output: 

👁 Image


Bitwise OR operation on Image:

Bit-wise disjunction of input array elements. 

Syntax: cv2.bitwise_or(source1, source2, destination, mask)
Parameters:
source1: First Input Image array(Single-channel, 8-bit or floating-point) 
source2: Second Input Image array(Single-channel, 8-bit or floating-point) 
dest: Output array (Similar to the dimensions and type of Input image array) 
mask: Operation mask, Input / output 8-bit single-channel mask 

Output: 

👁 Image

Bitwise XOR operation on Image:

Bit-wise exclusive-OR operation on input array elements. 

Syntax: cv2.bitwise_xor(source1, source2, destination, mask)
Parameters:
source1: First Input Image array(Single-channel, 8-bit or floating-point) 
source2: Second Input Image array(Single-channel, 8-bit or floating-point) 
dest: Output array (Similar to the dimensions and type of Input image array) 
mask: Operation mask, Input / output 8-bit single-channel mask 

Output:

👁 Image

Bitwise NOT operation on Image:

Inversion of input array elements. 

Syntax: cv2.bitwise_not(source, destination, mask)
Parameters: 
source: Input Image array(Single-channel, 8-bit or floating-point) 
dest: Output array (Similar to the dimensions and type of Input image array) 
mask: Operation mask, Input / output 8-bit single-channel mask 

Output:
Bitwise NOT on Image 1

👁 Image

Bitwise NOT on Image 2

👁 Image
Comment