List of Experiment: Department of Electronics & Communication Engg
List of Experiment: Department of Electronics & Communication Engg
)
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG.
Software LAB (MATLAB) (EC-506)
List of Experiment
Experiment-1
AIM: - To create Matrix of different types and performs basic operations on Matrix.
First, create a simple vector with 9 elements called a.
a = [1 2 3 4 6 4 3 4 5]
Creating a matrix is as easy as making a vector, using semicolons (;) to separate the rows of a
matrix.
A = [1 2 0; 2 5 -1; 4 10 -1]
A = 3×3
1 2 0
2 5 -1
4 10 -1
Instead of doing a matrix multiply, we can multiply the corresponding elements of two
matrices or vectors using the .* operator.
C = A.* B
C = 3×3
1 4 0
4 25 -10
0 -10 1
3×1
3.7321
0.2679
1.0000
As a simple example, you can add two vectors with the same size.
A = [1 1 1]
A=
1 1 1
B = [1 2 3]
B=
1 2 3
A+B
ans =
2 3 4
B = [3 0;1 5]
B=
3 0
1 5
A*B
ans =
6 15
10 20
The previous matrix product is not equal to the following element-wise product.
A.*B
ans =
3 0
2 20
SAGAR INSTITUTE OF RESEARCH AND TECHNOLOGY BHOPAL (M.P.)
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG.
Software LAB (MATLAB) (EC-506)
Experiment-2
AIM :- Analysis of amplitude modulation and its waveform.
clc;
close all;
clear all;
AM Modulation
y=Ac*(1+m*sin(2*pi*fa*t)).*sin(2*pi*fc*t);
subplot(3,1,3);
plot(t,y);
title ( ' Amplitude Modulated signal ');
xlabel ( ' time(sec) ');
ylabel (' Amplitud(volt) ');
grid on;
SAGAR INSTITUTE OF RESEARCH AND TECHNOLOGY BHOPAL (M.P.)
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG.
Software LAB (MATLAB) (EC-506)
Experiment-3
AIM: - To study image processing fundamentals and command.
imread()
The imread() command will read an image into a matrix:
img = imread('ImageProcessing_1/BerkeleyTower.png');
>> size(img)
ans =
499 748 3
imshow()
imshow() imagesc()
subplot(131);
SAGAR INSTITUTE OF RESEARCH AND TECHNOLOGY BHOPAL (M.P.)
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG.
Software LAB (MATLAB) (EC-506)
imagesc(img(:,:,1));
title('Red');
subplot(132);
imagesc(img(:,:,2));
title('Green');
subplot(133);
imagesc(img(:,:,3));
title('Blue');
subplot(211);
imshow(img);
title('Normal RGB');
subplot(212);
blue_img = double(img);
blue_img(:,:,3) = 4*blue_img(:,:,3);
blue_img = uint8(blue_img);
imshow(blue_img);
title('RG 4*B');
SAGAR INSTITUTE OF RESEARCH AND TECHNOLOGY BHOPAL (M.P.)
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG.
Software LAB (MATLAB) (EC-506)
Experiment-4
AIM:- To detect Edges of Different Images using different edge detector operators.
originalimage=imread('cameraman.tif');
subplot(2,3,1);
imshow(originalimage);
title('Original Image');
r=edge(originalimage,'roberts');
subplot(2,3,2);
imshow(r);
title('Roberts operator');
p=edge(originalimage,'prewitt');
subplot(2,3,3);
imshow(p);
title('Prewitt operator');
s=edge(originalimage,'sobel');
subplot(2,3,4);
imshow(s);
title('Sobel operator');
c=edge(originalimage,'canny');
subplot(2,3,5);
imshow(c);
title('Canny edge detector');
SAGAR INSTITUTE OF RESEARCH AND TECHNOLOGY BHOPAL (M.P.)
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG.
Software LAB (MATLAB) (EC-506)
Experiment-5
AIM:- To Remove of salt and pepper noise from image using median filter.
Median filtering is a nonlinear operation often used in image processing to reduce "salt and
pepper" noise. A median filter is more effective than convolution when the goal is to
simultaneously reduce noise and preserve edges. If the input image I is of an integer class,
then all the output values are returned as integers. If the number of pixels in the neighborhood
(i.e., m*n) is even, then some of the median values might not be integers. In these cases, the
fractional parts are discarded. Logical input is treated similarly.
I = imread('eight.tif');
figure,
subplot (1,3,1);
imshow(I)
J = imnoise(I,'salt & pepper',0.02);
subplot (1,3,2);
imshow(J)
K = medfilt2(J);
subplot (1,3,3);
imshow(K)
I = imread('eight.tif');
figure,
subplot (1,3,1);
imshow(I)
J = imnoise(I,'salt & pepper',0.02);
subplot (1,3,2);
imshow(J)
h= 1/3*ones(3,1);
SAGAR INSTITUTE OF RESEARCH AND TECHNOLOGY BHOPAL (M.P.)
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG.
Software LAB (MATLAB) (EC-506)
H=h*h';
K = filter2(H,J);
subplot (1,3,3);
imshow(uint8(K))
A = imread('cameraman.tif') ;
A = im2double(A);
[m n] = size(A);
Med = [];
Modified filter
for i=2:m-1
for j=2:n-1
Med(1) = A(i-1,j-1);
Med(2) =A(i-1,j) ;
Med(3) = A(i-1,j+1);
Med(4) = A(i,j-1);
Med(5) = A(i,j+1);
Med(6) = A(i+1, j-1);
Med(7) = A(i+1,j);
Med(8) = A(i+1,j+1);
A(i,j) = median(Med);
end
end
imshow(A);
Input image, specified as a 2-D grayscale or binary image. Neighborhood size, specified as a
2-element vector of real positive integers. Output image, returned as a numeric matrix of the
same class as the input image I.
SAGAR INSTITUTE OF RESEARCH AND TECHNOLOGY BHOPAL (M.P.)
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG.
Software LAB (MATLAB) (EC-506)
Experiment-6
AIM:- To study quality parameters of image processing.
Read image and create a copy with added noise. The original image is the reference image.
ref = imread('pout.tif');
A = imnoise(ref,'salt & pepper', 0.02);
∑ ∑ ( I ( i, j )− I^ (i , j) )
i=0 j=0
And Mean Square error (MSE) define as
2
] (8)
M −1 N −1
1 2
MSE=
MN
∑ ∑ ( I ( i , j )− ^I (i , j) ) (9)
i=0 j=0
Where M x N is size of the image I ( i , j ) represents original image and ^I ( i , j ) represents restored
image.
InputImage=imread(‘Input.jpg’);
ReconstructedImage=imread(‘recon.jpg’);
n=size(InputImage);
M=n(1);
N=n(2);
MSE = sum(sum((InputImage-ReconstructedImage).^2))/(M*N);
PSNR = 10*log10(256*256/MSE);
fprintf('\nMSE: %7.2f ', MSE);
fprintf('\nPSNR: %9.7f dB', PSNR);
image1=imread('image1.jpg');
image2=imread('image2.jpg');
psnr_=getPSNR(image1,image2);
ssim_=getMSSIM(image1,image2);
fprintf('PSNR= %f - SSIM= %f\n',psnr_,ssim_);
SAGAR INSTITUTE OF RESEARCH AND TECHNOLOGY BHOPAL (M.P.)
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG.
Software LAB (MATLAB) (EC-506)
Experiment-7
AIM:- Segment image into foreground and background using active contour.
activecontour(A,mask) segments the 2-D grayscale image A into foreground (object) and
background regions using active contour based segmentation. The output image bw is a
binary image where the foreground is white (logical true) and the background is black
(logical false). mask is a binary image that specifies the initial state of the active contour. The
boundaries of the object region(s) (white) in mask define the initial contour position used for
contour evolution to segment the image. To obtain faster and more accurate segmentation
results, specify an initial contour position that is close to the desired object boundaries.
I = imread('coins.png');
imshow(I)
title('Original Image');
mask = zeros(size(I));
mask(25:end-25,25:end-25) = 1;
figure, imshow(mask);
title('Initial Contour Location');
SAGAR INSTITUTE OF RESEARCH AND TECHNOLOGY BHOPAL (M.P.)
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG.
Software LAB (MATLAB) (EC-506)
bw = activecontour(I,mask,300);
figure, imshow(bw);
title('Segmented Image');
SAGAR INSTITUTE OF RESEARCH AND TECHNOLOGY BHOPAL (M.P.)
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG.
Software LAB (MATLAB) (EC-506)
Experiment-8
AIM:- Deblurring Images Using a Wiener Filter.
This example shows how to use Wiener deconvolution to deblur images. Wiener
deconvolution can be useful when the point-spread function and noise level are either known
or estimated. In signal processing, the Wiener filter is a filter used to produce an estimate of a
desired or target random process by linear time-invariant (LTI) filtering of an observed noisy
process, assuming known stationary signal and noise spectra, and additive noise. The Wiener
filter minimizes the mean square error between the estimated random process and the desired
process.
I = im2double(imread('cameraman.tif'));
imshow(I);
title('Original Image (courtesy of MIT)');
LEN = 21;
THETA = 11;
PSF = fspecial('motion', LEN, THETA);
blurred = imfilter(I, PSF, 'conv', 'circular');
imshow(blurred);
title('Blurred Image');
SAGAR INSTITUTE OF RESEARCH AND TECHNOLOGY BHOPAL (M.P.)
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG.
Software LAB (MATLAB) (EC-506)
Experiment-9
AIM:- Edge detection using morphological operation.
Morphology is a technique of image processing based on shapes. The value of each pixel in
the output image is based on a comparison of the corresponding pixel in the input image with
its neighbors. By choosing the size and shape of the neighborhood, you can construct a
morphological operation that is sensitive to specific shapes in the input image.
Dilation and erosion are two fundamental morphological operations. Dilation adds pixels to
the boundaries of objects in an image, while erosion removes pixels on object boundaries.
The number of pixels added or removed from the objects in an image depends on the size and
shape of the structuring element used to process the image.
The following sections describe the dilation and erosion functions in the toolbox:
Understanding Dilation and Erosion -- This section provides important background
information about how the dilation and erosion functions operate.
Structuring Elements -- This section describes structuring elements and how to create
them.
Dilating an Image -- This section describes how to use the imdilate function.
Eroding an Image -- This section describes how to use the imerode function.
Combining Dilation and Erosion -- This section describes some of the common
operations that are based on dilation and erosion.
Dilation- and Erosion-Based Functions -- This section describes toolbox functions
that are based on dilation and erosion
Morphological Reconstruction
BW2 = bwmorph(BW,'remove');
figure
imshow(BW2)
BW3 = bwmorph(BW,'skel',Inf);
figure
imshow(BW3)