You are on page 1of 17

SAGAR INSTITUTE OF RESEARCH AND TECHNOLOGY BHOPAL (M.P.

)
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG.
Software LAB (MATLAB) (EC-506)

List of Experiment

1. To create Matrix of different types and performs basic operations on


Matrix.
2. Analysis of amplitude modulation and its waveform.
3. To study image processing fundamentals and command.
4. To detect Edges of Different Images using different edge detector
operators.
5. To Remove of salt and pepper noise from image using median filter.
6. To study quality parameters of image processing.
7. Segment image into foreground and background using active contour.
8. Deblurring Images Using a Wiener Filter.
9. Edge detection using morphological operation.
SAGAR INSTITUTE OF RESEARCH AND TECHNOLOGY BHOPAL (M.P.)
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG.
Software LAB (MATLAB) (EC-506)

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

We can easily find the transpose of the matrix A.


B = A'
B = 3×3
1 2 4
2 5 10
0 -1 -1

Now let's multiply these two matrices together.


C=A*B
C = 3×3
5 12 24
12 30 59
24 59 117

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

There are functions to obtain eigenvalues ...


Eig (A)
ans =
SAGAR INSTITUTE OF RESEARCH AND TECHNOLOGY BHOPAL (M.P.)
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG.
Software LAB (MATLAB) (EC-506)

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

To see this, you can calculate the product of two matrices.


A = [1 3;2 4]
A=
1 3
2 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.

Amplitude modulation or AM as it is often called, is a form of modulation used for radio


transmissions for broadcasting and two way radio communication applications. According to
the standard definition, “The amplitude of the carrier signal varies in accordance with the
instantaneous amplitude of the modulating signal.” Which means, the amplitude of the carrier
signal containing no information varies as per the amplitude of the signal containing
information, at each instant.
SAGAR INSTITUTE OF RESEARCH AND TECHNOLOGY BHOPAL (M.P.)
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG.
Software LAB (MATLAB) (EC-506)

clc;
close all;
clear all;

disp(' example: m=1 means 100% modulation');


%m=input(' Enter the value of modulation index (m) = ');
m=1; % for 100% modulation
if (0>m||m>1)
error('m may be less than or equal to one and greater than to zero');
end

Modulating signal generation


Am=5;
fa=2000;
Ta=1/fa;
t=0:Ta/999:6*Ta;
ym=Am*sin(2*pi*fa*t);
figure(1)
subplot(3,1,1);
plot(t,ym), grid on;
title ( ' Modulating Signal');
xlabel ( ' time(sec) ');
ylabel (' Amplitude(volt)');

carrier signal generation


Ac=Am/m;
fc=fa*10;
Tc=1/fc;
yc=Ac*sin(2*pi*fc*t);
subplot(3,1,2);
plot(t,yc), grid on;
title ( ' Carrier Signal ');
xlabel ( ' time(sec) ');
ylabel (' Amplitud(volt) ');

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.

We'll use the following basic image processing functions:


1. imread()
2. imshow()
3. imwrite()
4. rgb2gray()
5. imhist()
6. imadjust()
7. im2bw()

imread()
The imread() command will read an image into a matrix:
img = imread('ImageProcessing_1/BerkeleyTower.png');

>> size(img)

ans =

499 748 3

imshow()

To show our image, we the imshow() or imagesc() command. The imshow() command


shows an image in standard 8-bit format, like it would appear in a web browser.
The imagesc()command displays the image on scaled axes with the min value as black and
the max value as white.

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))

function K = medfilt2(J); will be represented as

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);

MSE and PSNR Calculation :-

PSNR defines the performance of algorithm and it represents mathematically as


2552
PSNR=10 log
[ 1
MN
M −1 N−1

∑ ∑ ( 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);

Structural Similarity Index (SSIM):-

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)

wnr1 = deconvwnr(blurred, PSF, 0);


imshow(wnr1);
title('Restored 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

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

Morphological reconstruction is another major part of morphological image processing.


Based on dilation, morphological reconstruction has these unique properties:
 Processing is based on two images, a marker and a mask, rather than one image and a
structuring element
 Processing repeats until stability; i.e., the image no longer changes
SAGAR INSTITUTE OF RESEARCH AND TECHNOLOGY BHOPAL (M.P.)
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGG.
Software LAB (MATLAB) (EC-506)

 Processing is based on the concept of connectivity, rather than a structuring element.


BW = imread('circles.png');
imshow(BW);

BW2 = bwmorph(BW,'remove');
figure
imshow(BW2)

BW3 = bwmorph(BW,'skel',Inf);
figure
imshow(BW3)

You might also like