IW LabAssignment1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Name – Aditya Patil

Roll No-PA02
PRN-1032210569
Batch-A1

Course: IT Workshop Course Code: CET1066B

ASSIGNMENT NO: 1

Title: Introduction to Matlab and various Image Arithmetic and Logical Operations on
Image using MATLAB

Aim: To implement various Image Arithmetic and Logical Operations on Image using
MATLAB
Objectives:
1. To become familiar with Matlab environment.
2. To study basic Image Arithmetic and Logical Operations on Image
Theory (Describe the following):
● Key Features of MATLAB for Image Processing.
1. MATLAB is a powerful tool for image processing, offering a range of features
that make it suitable for this purpose:
2. Image Processing Toolbox:
a. Functions and Apps: Provides tools for image segmentation,
enhancement, noise reduction, geometric transformations, and image
registration.
b. Interactive Tools: Allows for region-of-interest (ROI) operations,
thresholding, and more through user-friendly interfaces.
3. Image Acquisition and Visualization:
a. Support for Various Formats: Handles common image file formats like
JPEG, PNG, TIFF, BMP, and more.
b. Image Visualization: Offers functions for displaying images, adjusting
contrast, and creating histograms.
4. Filtering and Transformations:
a. Spatial and Frequency Domain Filters: Includes convolution, Gaussian
filtering, Fourier transform, and wavelet transforms for image smoothing,
sharpening, and noise reduction.
b. Morphological Operations: Provides dilation, erosion, opening, closing,
and other operations for shape analysis.
5. Segmentation and Analysis:
a. Edge Detection and Thresholding: Functions for detecting edges and
segmenting images based on intensity values.
b. Region Properties: Calculates properties of segmented regions like area,
perimeter, and centroid.
6. Geometric Transformations:
a. Affine and Projective Transformations: Tools for rotating, scaling,
translating, and warping images.
b. Image Registration: Aligns images from different times or sensors.
7. Scripting and Automation:
a. Custom Scripts and Functions: Allows users to write custom scripts and
functions to automate repetitive tasks.
b. Batch Processing: Processes multiple images in a loop for large-scale
analysis.
8. Integration with Other Tools:
a. Simulink Integration: Works seamlessly with Simulink for model-based
design.
b. Interoperability: Communicates with other programming languages and
tools, such as Python, C/C++, and Java.

● Explain Image Arithmetic and Logical Operations

Image Arithmetic Operations involve mathematical manipulations performed on the pixel


values of images. These operations are used to combine, enhance, or analyze images in
various ways.

1. Addition:
○ Formula: Ioutput=I1+I2I_{output} = I_1 + I_2Ioutput=I1+I2
○ Use: Brightening images, creating composite images, and enhancing
features.
2. Subtraction:
○ Formula: Ioutput=I1−I2I_{output} = I_1 - I_2Ioutput
=I1−I2
○ Use: Detecting changes between images, motion detection, and
background subtraction.
3. Multiplication:
○ Formula: Ioutput=I1×I2I_{output} = I_1 \times I_2Ioutput=I1×I2
○ Use: Adjusting contrast, masking, and blending images.
4. Division:
○ Formula: Ioutput=I1/I2I_{output} = I_1 / I_2Ioutput=I1/I2
○ Use: Normalizing images, correcting illumination, and ratio-based
enhancement.

Image Logical Operations

Image Logical Operations involve pixel-wise logical operations between binary images
or between a binary image and a mask. These operations are essential for tasks like
segmentation, masking, and feature extraction.
1. AND Operation:
○ Formula: Ioutput=I1∧I2I_{output} = I_1 \land
I_2Ioutput=I1∧I2
○ Use: Isolating common regions between two images, noise reduction.
2. OR Operation:
○ Formula: Ioutput=I1∨I2I_{output} = I_1 \lor
I_2Ioutput=I1∨I2
○ Use: Combining regions of interest from multiple images.
3. XOR Operation:
○ Formula: Ioutput=I1⊕I2I_{output} = I_1 \oplus
I_2Ioutput=I1⊕I2
○ Use: Highlighting differences between images, edge detection.
4. NOT Operation:
○ Formula: Ioutput=¬II_{output} = \neg IIoutput=¬I
○ Use: Inverting binary images, creating negative images.

Platform:
● Matlab

Code:
clc;

%clear all;

close all;

%We will perform arithmetic operations on images.

%First read 2 images

x=imread('image1.jpg');

y=imread('image2.jpg');

%convert these images to black and white and resize the image for
bitwise

%operation

u=rgb2gray(x);

v=rgb2gray(y);

m=imresize(u,[256,256]);

n=imresize(v,[256,256]);

%displaying the image

subplot(4,4,1)

imshow(m);

title('image1');
subplot(4,4,2)

imshow(n);

title('image2');

%performing addition

sum=imadd(m,n);

subplot(4,4,3)

imshow(sum);

title('Arithmetic Addition');

%performing subtraction

diff1=imsubtract(m,n);

subplot(4,4,4)

imshow(diff1);

title('Img1 - Img2');

diff2=imsubtract(n,m);

subplot(4,4,5)

imshow(diff2);

title('Img2 - Img1');

%Performing multiplication

m1=im2double(m);

n1=im2double(n);

mul=immultiply(m1,n1);

subplot(4,4,6)

imshow(mul);

title('Multiplied Image');

%performing division

div1=imdivide(m1,n1);

subplot(4,4,7)

imshow(div1);

title('Div of img1 by img2');

div2=imdivide(n1,m1);

subplot(4,4,8)

imshow(div2);
title('Div of img2 by img1');

%performing logical operations

%Logical AND

and=bitand(m,n);

subplot(4,4,9)

imshow(and);

title('Logical AND');

%Logical OR

or=bitor(m,n);

subplot(4,4,10)

imshow(or);

title('OR operation');

%Logical NOT

not1=bitcmp(m); %bitwise complement

subplot(4,4,11)

imshow(not1);

title('Complement of Img 1');

not2=bitcmp(n); %bitwise complement

subplot(4,4,12)

imshow(not2);

title('Complement of Img 2');

%Logical XOR

xor=bitxor(m,n);

subplot(4,4,13)

imshow(xor);

title('EX OR operation');

%Logical NAND

nand=bitcmp(and);

subplot(4,4,14)

imshow(nand);

title('Logical Nand');

%Logical NOR
nor=bitcmp(or);

subplot(4,4,15)

imshow(nor);

title('NOR operation');

%Logical EX NOR

xnor=bitcmp(xor);

subplot(4,4,16)

imshow(xnor);

title('EX NOR operation');

OUTPUT

Conclusion:
This assignment helped to understand the working environment of Matlab and various
Image Arithmetic and Logical Operations.

FAQs:
1. What is MATLAB and what is it used for?
2. What are image arithmetic operations and why are they important?
3. What are image logical operations and how are they useful?

You might also like