Assignment 05 MOHAK
Assignment 05 MOHAK
Simulation Using
MATLAB
(EET 3351)
Branch: ECE
Section: B
Name Registration No. Signature
MOHAK CHAKRABORTY 2141003003
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)
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.
3 | Page
2.2 Output (Command Window and/or Plots)
output =
3 Question
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');
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.
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
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)
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
9 | Page