0% found this document useful (0 votes)
10 views9 pages

Assignment 05 MOHAK

This document is a lab assignment for EET 3351 focusing on modeling and simulation using MATLAB. It includes tasks such as designing image processing filters, creating plots for mathematical functions, and generating histograms for images. The assignment also requires students to implement MATLAB code for each task and analyze the outputs.

Uploaded by

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

Assignment 05 MOHAK

This document is a lab assignment for EET 3351 focusing on modeling and simulation using MATLAB. It includes tasks such as designing image processing filters, creating plots for mathematical functions, and generating histograms for images. The assignment also requires students to implement MATLAB code for each task and analyze the outputs.

Uploaded by

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

Modeling and

Simulation Using
MATLAB
(EET 3351)

LAB ASSIGNMENT SET – 05

Branch: ECE
Section: B
Name Registration No. Signature
MOHAK CHAKRABORTY 2141003003

Department of Electronics & Communication


Engineering
Institute of Technical Education and Research
(Faculty of Engineering)
Siksha ‘O’ Anusandhan (Deemed to be
University)
Bhubaneswar
1. Question
(a) Design a filter (for image processing) that will replace each pixel with an
average of all the neighboring pixel values.
(b)Redesign the above filter to include next nearest neighbors in computing
the average pixel value.

1.1. MATLAB Code

a.
clc
clear all
close all
A=[2 1 3 2 4 1;0 2 1 3 1 2;4 1 0 2 2 1;2 0 1 1 0 3;1 1 2 0 3 1]
[row,column]=size(A);
output=ones(row-2,column-2);
for i=2:row-1
for j=2:column-1
s1=0;
n=A(i-1:i+1,j-1:j+1)
s=sum(n);
s1=sum(s)/9
output(i-1,j-1)=s1;
end
end
output

b.
clc
clear all
close all
a=[2 1 3 2 4 1;0 2 1 3 1 2;4 1 0 2 2 1;2 0 1 1 0 3;1 1 2 0 3 1]
r=size(a,1);
c=size(a,2);
averageMat=ones(r-4,c-4);
for i=1:r-4
for j=1:c-4
k=a(i:i+4,j:j+4);
averageMat(i,j)=mean(mean(k));
end
end
disp('a-');
disp(a);
disp(averageMat)

1.2. Output (Command Window and/or Plots)


a. A =

2 1 3 2 4 1
0 2 1 3 1 2
4 1 0 2 2 1
2 0 1 1 0 3
1 1 2 0 3 1
output =

2 | Page
1.5556 1.6667 2.0000 2.0000
1.2222 1.2222 1.2222 1.6667
1.3333 0.8889 1.2222 1.4444

b.

a=

2 1 3 2 4 1
0 2 1 3 1 2
4 1 0 2 2 1
2 0 1 1 0 3
1 1 2 0 3 1

a-
2 1 3 2 4 1
0 2 1 3 1 2
4 1 0 2 2 1
2 0 1 1 0 3
1 1 2 0 3 1

1.5600 1.5200

2. Question
To prevent a reduction in the dimension of the filtered image, redesign
the above filter by padding the input image with zeros.

2.1 MATLAB Code


clc
clear all
close all
A=[2 1 3 2 4 1;0 2 1 3 1 2;4 1 0 2 2 1;2 0 1 1 0 3;1 1 2 0 3 1] %(5,6)
z=zeros(7,8)
z(2:6,2:7)=A
[row,column]=size(z);
output=ones(row-2,column-2);
for i=2:row-1
for j=2:column-1
s1=0;
n=z(i-1:i+1,j-1:j+1)
s=sum(n);
s1=sum(s)/9
output(i-1,j-1)=s1;
end
end
output

3 | Page
2.2 Output (Command Window and/or Plots)

output =

0.5556 1.0000 1.3333 1.5556 1.4444 0.8889


1.1111 1.5556 1.6667 2.0000 2.0000 1.2222
1.0000 1.2222 1.2222 1.2222 1.6667 1.0000
1.0000 1.3333 0.8889 1.2222 1.4444 1.1111
0.4444 0.7778 0.5556 0.7778 0.8889 0.7778

3 Question

Create a mesh, surface plot and contour plot of the function


−1 2 2
[x +0.5( x− y) ]
z ( x , y )=e 2 . Plot for the following interval −4 ≤ x ≤ 4 and −4 ≤ y ≤ 4 .

3.1 MATLAB Code

clc
clear all
close all
z_function = @(x, y) exp(-0.5 * (x.^2 + 0.5 * (x - y).^2));
[x, y] = meshgrid(-4:0.1:4, -4:0.1:4);
z = z_function(x, y);
subplot(3, 1, 1);
mesh(x, y, z);
title('Mesh Plot');

subplot(3,1,2 );
surf(x, y, z);
title('Surface Plot');
subplot(3,1,3);
contour(x, y, z);
title('Contour Plot');

4 | Page
3.2 Output (Command Window and/or Plots)

4 Question

Create a mesh, surface plot and contour plot of the function z=e x+iy for the
interval −1 ≤ x ≤1 and −2 π ≤ y ≤2 π . In each case plot the real part of z versus x and y.
4.1 MATLAB Code

clc
clear all
close all
zfunction = @(x, y) exp(x + 1i * y);
x = linspace(-1,1,100);
y = linspace(-2*pi,2*pi,100);
[x, y] = meshgrid(x, y);
z = zfunction(x, y);
real_part = real(z);
subplot(3, 1, 1);
mesh(x, y, real_part);

5 | Page
title('Mesh Plot (Real Part)');
xlabel('x');
ylabel('y');
subplot(3, 1, 2);
surf(x, y, real_part);
title('Surface Plot (Real Part)');
xlabel('x');
ylabel('y');
subplot(3, 1, 3);
contour(x, y, real_part);
title('Contour Plot (Real Part)');
xlabel('x');
ylabel('y');

4.2 Output (Command Window and/or Plots)

6 | Page
5 Question

Design a filter (for image processing) that will replace each pixel with an average of all
the neighboring pixel values. Consider stride as 2.

5.1 MATLAB Code


clc
clear all
close all
A=[2 1 3 2 4 1;0 2 1 3 1 2;4 1 0 2 2 1;2 0 1 1 0 3;1 1 2 0 3 1]
[row,column]=size(A);
output=ones(row-5,column-5);
for i=2:2:row-1
for j=2:2:column-1
Y(i/2,j/2)=(A(i,j)+A(i,j-1)+A(i,j+1)+A(i-1,j-1)+A(i-1,j)+A(i-
1,j+1)+A(i+1,j-1)+A(i+1,j)+A(i+1,j+1))/9;
end
end

5.2 Output (Command Window and/or Plots)

A=

2 1 3 2 4 1
0 2 1 3 1 2
4 1 0 2 2 1
2 0 1 1 0 3
1 1 2 0 3 1

Y=

1.5556 2.0000
1.3333 1.2222

6 Question

Write a Matlab program to plot histogram of a matrix of dimension 1024X1024.


Elements in the matrix must be random integers and in the range of 0 to 255. This
concept is used to create histogram of an image in image processing. Test your
program with a cameraman image.

6.1 MATLAB Code

clc;
clear all;
close all;
finalMatrix=[ ];

7 | Page
% A=round(255*rand(1024,1024));
A=imread('cameraman.tif');
[row,column]=size(A);
for a=0:255
x=0;
for i=1:row
for j=1:column
if a==A(i,j)
x=x+1;
end
end
end
finalMatrix(1,a+1)=x;
end
bar(0:255,finalMatrix)
xlabel('Pixel Intensity');
ylabel('Frequency');
title('Histogram');
figure
imshow(A)

6.2 Output (Command Window and/or Plots)

8 | Page
Histogram
1800

1600

1400

1200

1000
Frequency

800

600

400

200

0
-50 0 50 100 150 200 250 300
Pixel Intensity

7 Conclusion
Make a list of all the new MATLAB / Octave in-built functions that you learned
in this assignment set.
Sl. No. Function Name Short Description

(Signature of the Student)


Date:_____/____/_____

9 | Page

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy