0% found this document useful (0 votes)
15 views5 pages

18DIP Lab 5

The document describes bitwise logical operations that can be performed on images using OpenCV in Python, including AND, OR, XOR, and NOT. It explains how these operations can be used to calculate the intersection of two images, perform watermarking with XOR, and generate a negative image with NOT. The document provides code examples to demonstrate each operation and corresponding output images.

Uploaded by

Abdul Ahad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views5 pages

18DIP Lab 5

The document describes bitwise logical operations that can be performed on images using OpenCV in Python, including AND, OR, XOR, and NOT. It explains how these operations can be used to calculate the intersection of two images, perform watermarking with XOR, and generate a negative image with NOT. The document provides code examples to demonstrate each operation and corresponding output images.

Uploaded by

Abdul Ahad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

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:

You might also like