You are on page 1of 5

Bansilal Ramnath Agarwal Charitable Trust’s

Vishwakarma Institute of Technology, Pune-37


(An Autonomous Institute Affiliated to Savitribai Pune University)

Department of Electronics & Telecommunication Engineering

ET3221: Computer Vision

Name of the student: Vedant Bhagwan Roll No. 45


Div: ET-A Batch: 2
Date of performance: 07/07/23

Experiment No. 3

Problem Statement:

Logical Operations

AIM:

Write a Python Code for following Bitwise Operation:


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

Objective(s) of Experiment:

To perform the logical operation on the images

Introduction:

A standard logical operation can be performed between images such as NOT, OR, XOR, and
AND. In general, logical operation is performed between each corresponding bit of the image
pixel representation (i.e. a bit-wise operator).

▪ NOT (inversion): This inverts the image representation. In the simplest case of a
binary image, the (black) background pixels become (white) and vice versa.
▪ OR/XOR: are useful for processing binary-valued images (0 or 1) to detect
objects which have moved between frames. Binary objects are typically
produced through application of thresholding to a grey-scale image.
▪ Logical AND: is commonly used for detecting differences in images,
highlighting target regions with a binary mask or producing bit-planes through
an image.
Bansilal Ramnath Agarwal Charitable Trust’s
Vishwakarma Institute of Technology, Pune-37
(An Autonomous Institute Affiliated to Savitribai Pune University)

Department of Electronics & Telecommunication Engineering

Flowchart:
Bansilal Ramnath Agarwal Charitable Trust’s
Vishwakarma Institute of Technology, Pune-37
(An Autonomous Institute Affiliated to Savitribai Pune University)

Department of Electronics & Telecommunication Engineering

Code and Results

source1:

source2:

● AND:
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
Bansilal Ramnath Agarwal Charitable Trust’s
Vishwakarma Institute of Technology, Pune-37
(An Autonomous Institute Affiliated to Savitribai Pune University)

Department of Electronics & Telecommunication Engineering

● OR:
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

● XOR:
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
Bansilal Ramnath Agarwal Charitable Trust’s
Vishwakarma Institute of Technology, Pune-37
(An Autonomous Institute Affiliated to Savitribai Pune University)

Department of Electronics & Telecommunication Engineering

● NOT:
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

Conclusion:

Logical operators combine binary images, performing bitwise operations on integer images.
They are commonly used to invert images and detect differences between two images.

You might also like