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

S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING


I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

1.a) Image Flipping


Aim:
To write a MATLAB program to flip an image horizontally and diagonally.
Apparatus:
PC loaded with MATLAB 7.0 or above.
Program:
Clc;
clear all;
close all;
I = input('Enter the image name to be flipped');
I_i = imread(I);
I_ip = .2989*I_i(:,:,1) + .5870*I_i(:,:,2) +.1140*I_i(:,:,3);

figure();
imshow(I_ip);
title('Input image');

[m,n] = size(I_ip);

for i = 1:m for


j = 1:n
I_fh(i,j) = I_ip(i, n-j+1);
end
end

figure();
imshow(I_fh,[]);
title('Horizontally flipped image');

for i = 1:m for


j = 1:n
I_fv(i,j) = I_ip(m-i+1, j);
end
end

figure();
imshow(I_fv,[]);
title('Vertically flipped image');

for i = 1:m for


j = 1:n
I_fd(j,i) = I_ip(i,j);
End
end
figure();
imshow(I_fd,[]);
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

title('Diagonally flipped image');

Input (Command Window):


Enter the image name to be flipped:'peppers.png'
Output (Figure):

Result:

1.b) Image Cropping


S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

Aim:
To write a MATLAB program to crop an image.
Apparatus:
PC loaded with MATLAB 7.0 or above.
Program:
Clc;
clear all;
close all;

I = input('Enter the image name to be cropped');


I_i = imread(I);
I_ip = .2989*I_i(:,:,1) + .5870*I_i(:,:,2) +.1140*I_i(:,:,3);

[m,n] = size(I_ip);

imtool(I_ip);

j1 = input('The i index of first point:');


i1 = input('The j index of first point:');
j2 = input('The i index of second point:');
i2 = input('The j index of second point:');

for i = i1:1:i2 for


j = j1:1:j2
I_cr(i-i1+1,j-j1+1) = I_ip(i,j);
end
end

figure(); imshow(I_cr,
[]); title('Cropped
image');

Input (Imtool):
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

Input (Command Window):


Enter the image name to be cropped:
The i index of first point:
The j index of first point:
The i index of second point
The j index of second point:

Output (Figure):

Result

1.c) Mean, Variance and Histogram of an Image


Aim:
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

To write a MATLAB program to calculate the mean, variance and histogram of your image.
Apparatus:
PC loaded with MATLAB 7.0 or above.
Program:
Clc;
clear all;
close all;
I = input('Enter the input image name:');
I_i = imread(I);
I_ip = .2989*I_i(:,:,1) + .5870*I_i(:,:,2) +.1140*I_i(:,:,3);

figure();
imshow(I_ip);
title('Input image');

[m,n] = size(I_ip);

sum1 = 0; for
i = 1:1:m
for j = 1:1:n
I(i,j) = I_ip(i,j);
sum1 = sum1 + I(i,j);
end
end

mean_of_the_image = sum1/(m*n)

var_sum1 = 0;
for i = 1:1:m
for j = 1:1:n
I(i,j) = I_ip(i,j);
var_sum1 = var_sum1 + power((I(i,j)-mean_of_the_image),2);
end
end

variance_of_the_image = var_sum1/(m*n)

h = zeros(256,1);

for i = 1:1:m for


j = 1:1:n
for l = 1:1:256
if (l == I_ip(i,j))
h(l) = h(l) +1;
end
end
end
end
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

figure();

subplot(1,2,1);
imshow(I_ip);
title('Input Image');

subplot(1,2,2);
bar(h);
title('Histogram');
xlabel('Intensity value');
ylabel('Number of pixels');

Input & Output (Command Window):


Enter the input image name:

mean_of_the_image =

variance_of_the_image=

Output (Figure):

Result:

1.d) Square Root, Rounding, Normalization of an Image


Aim:
To write a MATLAB program to compute the square-root of your image, then rounding and to
show the result and its histogram, then normalize the rounded image and to show the histogram.
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

Apparatus:
PC loaded with MATLAB 7.0 or above.
Program:
Clc;
clear all;
close all;

[filename, pathname] = uigetfile(('*.tif;*.jpg;*.bmp;*.png'),


'Select the image');
if isequal(filename,0) |
isequal(pathname,0)
warndlg('User has stopped the
execution')
else

I_i = imread(filename);
I_ip = .2989*I_i(:,:,1) + .5870*I_i(:,:,2) +.1140*I_i(:,:,3);
[m,n] = size(I_ip);

for i = 1:1:m
for j =
1:1:n
I_sqt(i,j) =
sqrt(double(I_ip(i,j)));
I_rndsqt(i,j) = round(I_sqt(i,j));
end
end
I_nrmrndsqt = normr(I_rndsqt);

for i = 1:1:m
for j =
1:1:n
I_Hnrmrndsqt(i,j) = ceil(I_nrmrndsqt(i,j));
end
end

figure();
subplot(2,2,1);
imshow(I_ip,[]);
title('Original
image');
subplot(2,2,2);
bar(jkhist(I));
title('Histogram of Original image');

subplot(2,2,3);
imshow(I_sqt,[]);
title('Square root of Original image');

subplot(2,2,4);
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

bar(jkhist(I_sqt));
title('Histogram of Square rooted image');

figure();
subplot(2,2,1);
imshow(I_rndsqt,[]);
title('Rounded Square root of Original image');

subplot(2,2,2);
bar(jkhist(I_rndsqt));
title('Histogram of Rounded Square rooted image');

subplot(2,2,3);
imshow(I_nrmrndsqt,[]);
title('Normalised Rounded Square root of Original image');

subplot(2,2,4);
bar(jkhist(I_Hnrmrndsqt));
title('Histogram of Normalized Rounded Square rooted image');
end

function h = jkhist(I_ip)

h = zeros(256,1);
[m,n] = size(I_ip);

for i = 1:1:m for


j = 1:1:n
for l = 1:1:256
if (l == I_ip(i,j))
h(l) = h(l) +1;
end
end
end
end

Input (Browser):
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

Output (Figure):

Result:

1.d) Square Root, Rounding, Normalization of an Image


Aim:
To write a MATLAB program to compute the square-root of your image, then rounding and to
show the result and its histogram, then normalize the rounded image and to show the histogram.
Apparatus:
PC loaded with MATLAB 7.0 or above.
Program:
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

Clc;
clear all;
close all;

[filename, pathname] = uigetfile(('*.tif;*.jpg;*.bmp;*.png'),


'Select the image');
if isequal(filename,0) |
isequal(pathname,0)
warndlg('User has stopped the
execution')
else

I_i = imread(filename);
I_ip = .2989*I_i(:,:,1) + .5870*I_i(:,:,2) +.1140*I_i(:,:,3);
[m,n] = size(I_ip);

for i = 1:1:m
for j =
1:1:n
I_sqt(i,j) =
sqrt(double(I_ip(i,j)));
I_rndsqt(i,j) = round(I_sqt(i,j));
end
end
I_nrmrndsqt = normr(I_rndsqt);

for i = 1:1:m
for j =
1:1:n
I_Hnrmrndsqt(i,j) = ceil(I_nrmrndsqt(i,j));
end
end

figure();
subplot(2,2,1);
imshow(I_ip,[]);
title('Original
image');
subplot(2,2,2);
bar(jkhist(I));
title('Histogram of Original image');

subplot(2,2,3);
imshow(I_sqt,[]);
title('Square root of Original image');

subplot(2,2,4);
bar(jkhist(I_sqt));
title('Histogram of Square rooted image');

figure();
subplot(2,2,1);
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

imshow(I_rndsqt,[]);
title('Rounded Square root of Original image');

subplot(2,2,2);
bar(jkhist(I_rndsqt));
title('Histogram of Rounded Square rooted image');

subplot(2,2,3);
imshow(I_nrmrndsqt,[]);
title('Normalised Rounded Square root of Original image');

subplot(2,2,4);
bar(jkhist(I_Hnrmrndsqt));
title('Histogram of Normalized Rounded Square rooted image');
end

function h = jkhist(I_ip)

h = zeros(256,1);
[m,n] = size(I_ip);

for i = 1:1:m for


j = 1:1:n
for l = 1:1:256
if (l == I_ip(i,j))
h(l) = h(l) +1;
end
end
end
end

Input (Browser):

Output (Figure):
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

Result:

Output (Figure):
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

Result:

1.f) Logarithm and Normalization of an Image


Aim:
To write a MATLAB program to compute the logarithm and then to normalize the result and also
to print it together with its histogram

Apparatus:
PC loaded with MATLAB 7.0 or above.
Program:
Clc;
clear all;
close all;
[filename, pathname] = uigetfile(('*.tif;*.jpg;*.bmp;*.png'),
'Select the image');
if isequal(filename,0) |
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

isequal(pathname,0) warndlg('User has


stopped the execution')
else

I_i = imread(filename);

I_ip = .2989*I_i(:,:,1) + .5870*I_i(:,:,2) +.1140*I_i(:,:,3);

[m,n] = size(I_ip);

for i = 1:1:m
for j =
1:1:n
I_log(i,j) = log10(double(I_ip(i,j))+1);
end
end

B = normr(I_log);

figure();

subplot(2,2,1);
imshow(I_ip,[]);
title('Input
image');

subplot(2,2,2);
imshow(B,[]);
title('Normalized logarithmic image');

subplot(2,2,3);
bar(jkhist(I_ip));
title('Histogram of Input
image');
for i = 1:1:m for
j = 1:1:n
BH(i,j) = ceil(B(i,j));
end
end

subplot(2,2,4);
bar(jkhist(BH));
title('Histogram of Normalized logarithmic image');

end

function h = jkhist(I_ip)
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

h = zeros(256,1);
[m,n] = size(I_ip);

for i = 1:1:m for


j = 1:1:n
for l = 1:1:256
if (l == I_ip(i,j))
h(l) = h(l) +1;
end
end
end
end

Output (Figure):
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

Result:

2.a) Computation of Transform of image by


different Transforms
Aim:
To write a MATLAB program to compute the transformation of moon.jpg image using DCT,
DST, Walsh-Hadamard, Radon and Wavelet transform, and reconstruction from the transformed
image as well.

Apparatus:
PC loaded with MATLAB 7.0 or above.
Program:
clc;
clear all;
close all;
RGB=imread('moon.jpg');
I = rgb2gray(RGB);
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

figure();
imshow(I,[]);
title('Original
Image');

figure();
J = dct2(I);
subplot(1,2,1
);
imshow(abs(J)
);
title('DCT');
i = idct2(J);
subplot(1,2,2
); imshow(i,
[]);
title('Reconstructed from DCT');

figure()
; J =
dst(I);
subplot(1,2,1);
imshow(abs(J));
title('DST');
i = idst(J);
subplot(1,2,2
); imshow(i,
[]);
title('Reconstructed from DST');

figure()
J =
fwht(double(I));
subplot(1,2,1);
imshow(abs(J)); title('Walsh-
Hadamard Transform'); i =
ifwht(J);
subplot(1,2,2);
imshow(i,[]);
title('Reconstructed from Walsh-Hadamard Transform');

figure()
J = radon(I,0:179);
subplot(1,2,1);
imshow(abs(J));
title('RADON Transform');
i = iradon(J,0:179);
subplot(1,2,2); imshow(i,
[]);
title('Reconstructed from Radon Transform');

figure();
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

[A,H,V,D] = dwt2(I,'db4');
dec=[...
A,H
V,D
...
];
subplot(1,2,1);
imshow(dec,[]);
title('WAVELET Transform');
i = idwt2(A,H,V,D,'db4');
subplot(1,2,2); imshow(i,
[]);
title('Reconstructed from Wavelet Transform');

Output (Figure):

Result:

2.b) Computation of 2D DFT


Aim:
To write a MATLAB program to compute the 2D DFT of the 4x4 gray scale image
1 2 3 4


5 6 7 8
f (m, n) .
1 2 3 4

6 7 8
Apparatus:
PC loaded with MATLAB 7.0 or above.
Program:
clc;
clear all;
close all;
i_p = input('Enter the input signal:');
d_m = jkdftmtx(size(i_p));
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

D_T = d_m*i_p*(d_m)';
disp('The DFT of the given signal is;');
disp(D_T);

function D = jkdftmtx(N)
f = 2*pi./N;
w = (0:f:2*pi-f/2).' * 1i;
x = 0:N-1;
D = exp(-w*x);
end

Output (Command Window):


Enter the input signal:[ ]
The DFT of the given signal is;

Result:

The hadamrd matrix is

The inverse of the hadamard matrix is:


S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

Result:

2.d) Computation of KL Transform


Aim:
To write a MATLAB program to compute KL Transform of cameraman.tif image.

Apparatus:
PC loaded with MATLAB 7.0 or above.
Program:
clc;
closeall;
clearall;
I=imread('cameraman.tif');
I=im2double(I);
m=1;
for i=1:8:256
for
j=1:8:256
for x=0:7
for
y=0:7
img(x+1,y+1)=I(i+x,j+y)
; end
end
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

k=0;
for l=1:8
img_expect{k+1}=img(:,l)*img(:,l)';
k=k+1;
end
imgexp=zeros(8:8
); for l=1:8
imgexp=imgexp+(1/8)*img_expect{l};%expectation of E[xx']
end
img_mean=zeros(8,1)
; for l=1:8
img_mean=img_mean+(1/8)*img(:,l);
end
img_mean_trans=img_mean*img_mean'
;
img_covariance=imgexp -
img_mean_trans;
[v{m},d{m}]=eig(img_covariance);
temp=v{m};
m=m+1;
for
l=1:8
v{m-1}(:,l)=temp(:,8-(l-1));
end
for l=1:8 trans_img1(:,l)=v{m-
1}*img(:,l);
end
for x=0:7
for y=0:7
transformed_img(i+x,j+y)=trans_img1(x+1,y+1);
end
end
mask=[1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 ];
trans_img=trans_img1.*mask;
for l=1:8
inv_trans_img(:,l)=v{m-1}'*trans_img(:,l);
end
for x=0:7 for
y=0:7
inv_transformed_img(i+x,j+y)=inv_trans_img(x+1,y+1);
end
end
end
end
figure();
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

imshow(I,[]); title('Input image');


figure();
imshow(transformed_img);title('KL Transform of input image');
figure();
imshow(inv_transformed_img);title('Reconstructed image from KL Transform');

Output (Figure):

Result:

2.e) Verification of Unitary Matrix


Aim:
1
To write a MATLAB program to determine whether the matrix A 1 1
is unitary or not
1
2 1
with justification

Apparatus:
PC loaded with MATLAB 7.0 or above.
Program:
clc;
clearal1
;
A = input('Enter the matrix
(A):'); AT = A';
AH = conj(AT);
if (round(A^(-1) - AH) == zeros(size(A)))
disp('The given matrix is Unitary
Matrix');
else
disp('The given matrix is not an Unitary matrix');
end
disp('A='
);
disp(A);
disp('A*AH(for Unitary it must be I) =
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

'); disp(A*AH);

Output (Command Window):


Enter the matrix (A): The given matrix
is Unitary Matrix
A=

A*AH(for Unitary it must be I) =

Result:

2.f) Computation of 2D Haar Transform


Aim:
4 1
To write a MATLAB program to determine the 2D Haar transform of the signal f (m, n)
2
3
Apparatus:
PC loaded with MATLAB 7.0 or above.
Program:
clc;
clear
all;
close
all;
i_p = input('Enter the input signal:');
h_m = (1/sqrt(2))*[1,1;1,-1];
H_T = h_m*i_p*(h_m)';
disp('The Haar transform of the given signal
is;'); disp(H_T);

Output (Command Window):


Enter the input signal:[4,-1;2,3]
The Haar transform of the given signal
is; 4.0000 2.0000 -1.0000
3.0000
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

Result:

2.g) Computation of DCT and DST Matrix


Aim:
To write a MATLAB program to determine the DCT and DST matrices for N=4.

Apparatus:
PC loaded with MATLAB 7.0 or above.
Program:
clc; clear
all; close
all;

N = input('Enter the value of N:');

c = jkdctmtx(N);
s = jkdstmtx(N);

disp('The DCT matrix for N=4 is:');


disp(c);

disp('The DST matrix for N=4 is:');


disp(s);

function c = jkdctmtx(N)

[n,k] = meshgrid(0:N-1);
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

c = sqrt(2/N) * cos(pi*(2*n+1).*k/(2*N));
c(1,:) = c(1,:) / sqrt(2);
end

function s = jkdstmtx(N)

[n,k] = meshgrid(0:N-1);

s = sin(pi.*k.*n/(N+1));
end

Output (Command Window):


Enter the value of N:

The DCT matrix for N= is:

The DST matrix for N= is:

Result:
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

3.a) Histogram of shuffled image


AIM:
To write a MATLAB program If all the pixels of the image are shuffled. What is the change in
histogram.

PROGRAM:
clc;
clear all;
close all;
a=imread('cameraman.tif');
b=fliplr(a);
subplot(2,2,1);
imshow(a);
title('original image');
subplot(2,2,2);
imshow(b);
title('flipped image');
subplot(2,2,3);
imhist(a);
subplot(2,2,4);
imhist(b);

output:

Result:
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

3.b)Different Types of noises


AIM:
To write a MATLAB program apply different types of noises to an image.
PROGRAM:
clc;
clear all;
close all;
I=imread('cameraman.tif');
noise_mean=0.5;
noise_var=0.0001;
J=imnoise(I,'salt & pepper',0.02);
k=imnoise(I,'gaussian',noise_mean, noise_var);
l=imnoise(I,'poisson');
m=imnoise(I,'speckle',0.5);
imshow(I);
figure()
title('original image');
subplot(2,2,1);
imshow(J);
title('salt and pepper noise');
subplot(2,2,2);
imshow(k);
title('gaussiannoise');
subplot(2,2,3);
imshow(l);
title('poisson noise');
subplot(2,2,4);
imshow(m);
title('speckle noise');
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

INPUT

OUTPUT:

RESULT:
3.c)Median filtering
AIM:
To write a MATLAB program show that median filter is effective tool to minimize salt and
pepper noise
PROGRAM
clc;
clear all;
close all;
I=imread('eight.tif');
figure()
imshow(I);
title('original image');
J=imnoise(I,'salt & pepper',0.02);
figure()
subplot(1,2,1)
imshow(J);
title('salt and pepper noise');
L=medfilt2(J);
subplot(1,2,2);
imshow(L);
title('removing salt and pepper noise by median filter');
INPUT
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

OUTPUT:

RESULT:

3.d)Homomorphic Filtering
AIM:
To write a MATLAB program apply homomorphic filtering to an image
PROGRAM:
clc;
close all;
clear all;
d=10;
order=2;
im=double(imread('cameraman.tif'));
subplot(2,2,1);
imshow(im./255);
title('input image');
[r,c]=size(im);
homofil(im,d,r,c,order);
function homofil(im,d,r,c,n)
A=zeros(r,c);
for i=1:r
for j=1:c
A(i,j)=(((i-r/2).^2+(j-c/2).^2)).^(.5);
H(i,j)=1/(1+((d/A(i,j))^(2*n)));
end
end
alphaL=0.0999;
alphaH=1.01;
H=((alphaH-alphaL).*H)+alphaL;
H=1-H;
%log of image
im_1=log2(1+im);
%dft of logged image
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

im_f=fft2(im_1);
%filter applying dft image
im_nf=H.*im_f;
%inverse dft of filtered image
im_n=abs(ifft2(im_nf));
%inverse log
im_e=exp(im_n);
subplot(1,2,2);
imshow((im_e),[]);
title('output image');
figure();
imshow(H);
title('output of butterworth hpf');
OUTPUT:

RESULT:
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

3.e)Histogram Equalization
AIM:
To write a MATLAB program apply histogram equalization of an image.

PROGRAM:
clc;
clear all;
close all;
I1= imread('cameraman.tif');
[m,n] = size(I1);
disp(m);
disp(n);
for i = 1:1:m
for j = 1:1:n
I2(i,j) = sqrt(double(I1(i,j)));
end
end
I3 = normr(I2);
figure();
subplot(2,2,1);
imshow(I1,[]);
title('Original image');
subplot(2,2,2);
imhist(I1);
title('Histogram of Original image');
subplot(2,2,3);
imshow(I2,[]);
title('Square root of Original image');
subplot(2,2,4);
imhist(I2);
title('Histogram of Square rooted image');
figure,
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

subplot(1,2,1);
imshow(I3,[]);
title('Normalised Square root of Original image');
subplot(1,2,2);
imhist(I3);
title('Histogram of Normalized Square rooted image');

OUTPUT:

RESULT:
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

4.a) EDGE DETECTION


AIM:
To write a MATLAB program obtain the frequency response of the following edge detectors.
a) prewitt operator b) sobel operator c) laplacian operator d) Roberts operator e)canny operator

PROGRAM:
clc;
clear all;
close all;
a=imread('coloredChips.png');
a=rgb2gray(a);
b=edge(a,'roberts');
c=edge(a,'sobel');
d=edge(a,'prewitt');
e=edge(a,'log');
f=edge(a,'canny');
figure();
subplot(2,3,1);
imshow(a);
title('input image');
subplot(2,3,2);
imshow(b);
title('roberts detection');
subplot(2,3,3);
imshow(c);
title('sobel detection');
subplot(2,3,4);
imshow(d);
title('prewitt detection');
subplot(2,3,5);
imshow(e);
title('log detection');
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

subplot(2,3,6);
imshow(f);
title('canny detection');
OUTPUT:

RESULT:

4.b)IMAGE TECHNIQUES
AIM:
To write a MATLAB program apply dilation,erosion,opening ,closing of an image with a black
background [0000000;0011000;0001000;0001100;0011110;0011110;0011100;0000000]

PROGRAM:
clc;
clear all;
close all;
BW=[0 0 0 0 0 0 0;0 0 1 1 0 0 0;0 0 0 1 0 0 0;0 0 0 1 1 0 0;0 0 1 1 1 1 0;0 0 1 1 1 1 0;0 0 1 1 1 0
0;0 0 0 0 0 0 0];
figure();
imshow(BW);
SE1=strel('line',3,0);
N=imdilate(BW,SE1);
figure();
imshow(N);
N2=imerode(BW,SE1);
figure();
imshow(N2);
N3=imopen(BW,SE1);
figure();
imshow(N3);
N4=imclose(BW,SE1);
figure();
imshow(N4);

INPUT:
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

OUTPUT:

RESULT:
4.c)EROSION

AIM:
To write a MATLAB program for erode using structure element
BW= [0 0 0 0 0 0 0 0 0 ;0 0 0 0 0 1 0 0 0 0; 0 0 1 0 0 1 0 0 0 0;0 0 1 1 1 1 1 0 0 0;0 0 1 0 1 1 0 0
0 0;0 0 1 0 1 1 0 0 0 0; 0 0 1 0 1 0 0 0 0 ; 0 1 1 1 1 1 1 1 0 0; 0 0 0 0 0 1 1 0 0 0;0 0 0 0 0 0 0 0 0
0]
SE=[1 0 0;1 0 1;0 0 0];

PROGRAM:
clc;
close all;
clear all;
BW=[0 0 0 0 0 0 0 0 0 0
0000010000
0010010000
0011111000
0010110000
0010110000
0010100000
0111111100
0000011000
0 0 0 0 0 0 0 0 0 0];
SE=[1 0 0
101
0 0 0];
I=imerode(BW,SE);
figure();
imshow(BW);
figure();
imshow(SE);
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

figure();
imshow(I);

INPUT:

OUTPUT:

RESULT:
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

5.a)BTC
AIM:
To write a MATLAB program read an image apply BTC using different block sizes

PROGRAM:
clc;
close all;
x=imread('coins.png');
x=imresize(x,[256 256]);
x1=x;
x=double(x);
[m1, n1]=size(x);
blk=input('block size');
for i=1:blk:m1
for j=1:blk:n1
y=x(i:i+(blk-1),j:j+(blk-1));
m=mean(mean(y));
sig=std2(y);
b=y>m;
k=sum(sum(b));
if (k~=blk^2)&&(k~=0)
m1=m-sig*sqrt(k\((blk^2)-k));
mu=m+sig*sqrt(((blk^2)-k)/k);
x(i:(i+(blk-1)),j:(j+(blk-1)))=b*mu+(1-b)*m1;
end
end
end
figure
imshow(x1);
title('original image');
figure
imshow(b);
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

title('reconstructed image');
OUTPUT:

RESULT:

5.b)DCT
AIM:
To write a MATLAB program apply DCT to an image
\
PROGRAM:
clc;
close all;
i=imread('coins.png');
i=double(i)/255;
subplot(211);
imshow(i);
title('original image');
img_dct=dct2(i);
img_pow=(img_dct).^2;
img_pow=img_pow(:);
[b,index]=sort(img_pow);
b=flipud(b);
index=flipud(index);
compressed_dct=zeros(size(i));
coeff=20000;
for k=1:coeff
compressed_dct(index(k))=img_dct(index(k));
end
im_dct=idct2(compressed_dct);
subplot(212)
imshow(im_dct);
title('dct compress image');
imwrite(im_dct,'compress.png');
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

OUTPUT:

RESULT:

5.c)WAVELET TRANSFORM
Aim:
To write a MATLAB program to decompose an image and then to reconstruct from the wavelet
transform

Program:
clc;
WLT = input('Enter the wavelet to apply on image(with quotes):');
disp('Reading input image....');
img = input('Enter the name of the input image (with quotes):');
x = imread(img);
xx = x;
disp('Applying the wavelet on the image....');
[cA,cH,cV,cD] = dwt2(x,WLT);
disp('Done.');
xRec = idwt2(cA, cH, cV, cD, WLT);
disp('Mean Square Error:');
disp('Peak Signal to Noise Ratio (dB):');
Out=uint8(xRec);
subplot(2,2,1);
title('Input image');
title('Transformed Image');
imshow(Out); title('Reconstructed image');

OUTPUT WINDOW
S V UNIVERSITY COLLEGE OF ENGINEERING,TIRUPATI
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
I M.Tech II Sem, Communication Systems Image Processing Lab Record Roll No:

OUTPUT FIGURE

RESULT

You might also like