Lab Manual # 5
“To Write and Execute Programs for Image Logical Operations”
Objective:
• AND operation between two images
• OR operation between two images
• Calculate intersection of two images
• Water Marking using EX -OR operation
• NOT operation (Negative image)
Apparatus:
• PC/Laptop with Windows 7/8/8.1/10
• PyCharm Version: 2022.1.1
Theory:
Bitwise operations are used in image manipulation and used for extracting essential
parts in the image. In this article, Bitwise operations used are:
• AND
• OR
• XOR
• 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 01:
Input Image 02:
I. AND Operation Between two Images:
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)
• Destination: Output array (Similar to the dimensions and type of Input image array)
• Mask: Operation mask, Input / output 8-bit single-channel mask
Input Code:
Output:
II. OR Operation Between two Images:
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)
• Destination: Output array (Similar to the dimensions and type of Input image array)
• Mask: Operation mask, Input / output 8-bit single-channel mask
Input Code:
Output:
III. Calculate Intersection of two images:
For the intersection between the two binary images, bitwise_and, bitwise_or or
bitwise_xor can be used
Input Code:
Output:
Using AND Using OR Using XOR
IV. Water Marking using EX -OR operation:
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)
• Destination: Output array (Similar to the dimensions and type of Input image array)
• Mask: Operation mask, Input / output 8-bit single-channel mask
V. Bitwise NOT operation on Image:
Syntax:
cv2.bitwise_not(source, destination, mask)
Parameters:
• Source: Input Image array(Single-channel, 8-bit or floating-point)
• Destination: Output array (Similar to the dimensions and type of Input image array)
• Mask: Operation mask, Input / output 8-bit single-channel mask
Input Code:
Output:
Bitwise NOT on Input Image 01 Bitwise NOT on Input Image 02
Conclusion: