Bitwise operations are used in image manipulation and are used to extract important parts of an image. This article uses bitwise operations:
AND
OR
XOR
NO
Bitwise operations also help in masking images. Imaging can be enabled using these operations. These operations can be useful for improving the properties of the input images.
Note: Bitwise operations must be applied on input images of the same size
Input image 1 :
Input Image 2:
Bitwise operation AND on the image:
Bitwise connection of elements of the input array.
Parameters: source1: First Input Image array (Single- channel, 8-bit or floating-point) source2: Second Input Image array (Single-channe l, 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
# Python illustration program # arithmetic operation # bitwise AND of two images
# organization of import
import cv2
import numpy as np
# specifies the path to the input images and # images are loaded using the imread command
image1 = cv2.imread ( ’input1.jpg’ )
image2 = cv2.imread ( ’input2.jpg’ )
# cv2.bitwise_and is applied over # input images with applied parameters
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 Inpu t image array) mask: Operation mask, Input / output 8-bit single-channel mask
# Python program for illustration # arithmetic operation # bitwise OR of two images
# organization of import
import cv2
import numpy as np
# specifies the path to input images and # images are loaded using imread command
image1 = cv2.imread ( ’input1.jpg’ )
image2 = cv2.imread ( ’input2.jpg’ )
# cv2.bitwise_or applied over # image input with parameters applied
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 an d type of Input image array) mask: Operation mask, Input / output 8-bit single-channel mask
# Python illustration program # arithmetic operation # bitwise XOR of two images
# organizing imports
import cv2
import numpy as np
# specifies the path to the input images and # images are loaded using imread
image1 = cv2.i mread ( ’input1.jpg’ )
image2 = cv2.imread ( ’input2.jpg’ )
# cv2. bitwise_xor is applied over # image input with parameters applied