Index: Name:-Fadadu Sharad Roll No.: - P10Ec949
Index: Name:-Fadadu Sharad Roll No.: - P10Ec949
PRACTICAL:-01
P10EC949 Page:-
DIP Lab S.V.N.I.T.
Program:-
clc; clear all; close all;
I=imread('peppers.png');
J=rgb2gray(I);
subplot 221; imshow(I);
title('Original RGB Image');
subplot 222; imshow(J);
title('Gray Image');
[K,map]=rgb2ind(I,128);
M=ind2rgb(K,map);
subplot 223; imshow(M);
title('Indexed RGB Image 128 Color Levels');
[L,map]=gray2ind(J,128);
N=ind2gray(L,map);
subplot 224; imshow(N);
title('Indexed Gray Image 128 Gray Levels');
PRACTICAL:-02
P10EC949 Page:-
DIP Lab S.V.N.I.T.
Program :-
f=double(f);
s=10*(1+log(f)); s=uint8(s);
subplot 236; imshow(s);
title('After Logarithmic');
PRACTICAL:-03
P10EC949 Page:-
DIP Lab S.V.N.I.T.
Program:-
end;
end;
subplot 131; imshow(h);
title('Original Image');
subplot 132; imshow(H1);
title('With White back ground');
subplot 133; imshow(H2);
title('With No back ground');
Output:-
PRACTICAL:-04
P10EC949 Page:-
DIP Lab S.V.N.I.T.
Program:-
for a=1:m,
for b=1:n,
hist1(h(a,b)+1)=hist1(h(a,b)+1)+1; % Occurance of gray value
end;
end;
a=0:255;
subplot 222; stem(a,hist1);
set(gca,'Xlim',[0 255]);
title('Histogram of Original');
for a=1:256,
hist2(a)=0;
end;
for a=1:m,
for b=1:n,
g(a,b)=s(h(a,b)+1); % New Gray Value Mapping
hist2(g(a,b)+1)=hist2(g(a,b)+1)+1; % Occurance of Gray
end;
end;
a=0:255;
subplot 224; stem(a,hist2);
set(gca,'Xlim',[0 255]);
title('Histogram of Modified');
PRACTICAL:-05
P10EC949 Page:-
DIP Lab S.V.N.I.T.
Program:-
f=imread('cameraman.tif');
subplot 331; imshow(f);
title('Original Image');
[m,n]=size(f);
for c=1:8,
for a=1:m,
for b=1:n,
h1(c,a,b)=bitand(uint8(f(a,b)),uint8(2^(c-1)));
% Mask other bits
end;
end;
end;
for c=1:8,
g(:,:)=h1(c,:,:); % Create Image For each Plane
subplot (3,3,c+1); imshow(g);
title(['Bit-Sliced (Plane :- ',num2str(c),')']);
end;
g1(:,:)=h1(5,:,:)+h1(6,:,:)+h1(7,:,:)+h1(8,:,:);
figure,
subplot 121; imshow(f);
title('Original Image');
subplot 122; imshow(g1);
title('Summation of plane 5,6,7 and 8');
PRACTICAL:-06
P10EC949 Page:-
DIP Lab S.V.N.I.T.
AIM:- Read an image and perform Average and Weightage lowpass filter in spatial domain
for 3x3 and 5x5 mask.
Program:-
f=imread('eight.tif');
f=f(20+[1:180],50+[1:180]); %crop an Image
subplot 231; imshow(f);
title('Original Image');
PRACTICAL:-07
P10EC949 Page:-
DIP Lab S.V.N.I.T.
AIM:- Read an Image, corrupt it by Salt-Pepper noise, Gaussian noise and Speckle noise.
Apply 3x3 & 5x5 box filter and comment on the result.
Program:-
f=imread('rice.png');
subplot 221; imshow(f);
title('Original Image');
a=1/(3*3).*ones(3);
g1=conv2(double(g),double(a),'same');
g1=uint8(g1);
a=1/(5*5).*ones(5);
g2=conv2(double(g),double(a),'same');
g2=uint8(g2);
PRACTICAL:-08
P10EC949 Page:-
DIP Lab S.V.N.I.T.
AIM:- Read an Image, corrupt it by Salt-Pepper noise. Apply 3x3 & 5x5 box filter and
Median Filter. Comment on obtained result.
Program:-
f=imread('coins.png');
f=f(20+[1:180],20+[1:256]); %crop an Image
subplot 321; imshow(f);
title('Original Image');
a=1/(3*3).*ones(3);
g1=conv2(double(g),double(a),'same');
g1=uint8(g1);
subplot 323; imshow(g1);
title('Result of 3x3 box filter');
a=1/(5*5).*ones(5);
g1=conv2(double(g),double(a),'same');
g1=uint8(g1);
subplot 324; imshow(g1);
title('Result of 5x5 box filter');
g2=medfilt2(g,[3 3]);
subplot 325; imshow(g2);
title('Result of 3x3 Median filter');
g2=medfilt2(g,[5 5]);
subplot 326; imshow(g2);
title('Result of 5x5 Median filter');
PRACTICAL:-09
P10EC949 Page:-
DIP Lab S.V.N.I.T.
Program:-
f=imread('moon.tif');
[m n]=size(f);
f=f(0+[1:m],30+[1:n-80]);
PRACTICAL:-10
P10EC949 Page:-
DIP Lab S.V.N.I.T.
Program:-
num=1;
for lop=1:2,
m=50; n=50;
ord=2*lop+1;
Mask=1/(ord*ord).*ones(ord); % Generate Mask
subplot (2,2,num+1);
surf((a*2*pi/m)-pi,(b*2*pi/n)-pi,abs(Y1));
set(gca,'xlim',[-pi pi],'xtick',(-pi:pi/2:pi),
'xticklabel',{'-pi','-pi/2','0','pi/2','pi'});
set(gca,'ylim',[-pi pi],'ytick',(-pi:pi/2:pi),
'yticklabel',{'-pi','-pi/2','0','pi/2','pi'});
xlabel('\omega_x (rad)');
ylabel('\omega_y (rad)');
zlabel('Magnitude');
title(['Freq Responce of Mask:- ',num2str(ord)','X',
num2str(ord),' with fftshift']);
num=num+2;;
end;
PRACTICAL:-11
P10EC949 Page:-
DIP Lab S.V.N.I.T.
Program:-
h=conv2(f,g);
h=uint8(h);
subplot 223; imshow(h);
title('Spatial Convolution');
m=m1+m2-1; n=n1+n2-1;
Y1=fft2(f,m,n); % Fourier of 1
Y2=fft2(g,m,n); % Fourier of 2
PRACTICAL:-12
P10EC949 Page:-
DIP Lab S.V.N.I.T.
AIM:- For the given two images find Magnitude and Phase of each Image. Interchange the
Phase and Magnitude with each other and reconstruct the images. Comment on the
result.
Program:-
f=imread('cameraman.tif');
g=imread('rice.png');
[m n]=size(f);
PRACTICAL:-13
P10EC949 Page:-
DIP Lab S.V.N.I.T.
AIM:- Generate an Image having a Square on centre of dimension 50x50 and Rotate this
Image at 45 degree. Find Spectrum of Original and Rotated Images.
Program:-
f=[ zeros(50),zeros(50),zeros(50);
zeros(50), ones(50),zeros(50);
zeros(50),zeros(50),zeros(50)];
Y1=fftshift(fft2(f,50,50));
Y2=fftshift(fft2(g,50,50));
PRACTICAL:-14
P10EC949 Page:-
DIP Lab S.V.N.I.T.
AIM:- Get an Image consisting of white square with black back ground. Rotate image 30 &
45 degree and observe i) Imrotate using nearest option and ii) Using bilinear option.
Program:-
g=imrotate(f,30,'nearest');
subplot 221; imshow(g);
title('Rotated 30^o For Nearest Option');
g=imrotate(f,45,'nearest');
subplot 222; imshow(g);
title('Rotated 45^o For Nearest Option');
g=imrotate(f,30,'bilinear');
subplot 223; imshow(g);
title('Rotated 30^o For Bilinear Option');
g=imrotate(f,45,'bilinear');
subplot 224; imshow(g);
title('Rotated 45^o For Bilinear Option');
PRACTICAL:-15
P10EC949 Page:-
DIP Lab S.V.N.I.T.
Program:-
Y=fftshift(fft2(f,m,n));
YI=Y.*H;
YB=Y.*HB;
YG=Y.*HG;
yi=ifft2(fftshift(YI));
yb=ifft2(fftshift(YB));
yg=ifft2(fftshift(YG));
PRACTICAL:-16
P10EC949 Page:-
DIP Lab S.V.N.I.T.
Program:-
Y=fftshift(fft2(f,m,n));
YI=Y.*H;
YB=Y.*HB;
YG=Y.*HG;
yi=ifft2(fftshift(YI));
yb=ifft2(fftshift(YB));
yg=ifft2(fftshift(YG));
PRACTICAL:-17
P10EC949 Page:-
DIP Lab S.V.N.I.T.
AIM:- Observe Band reject filter in frequency domain as periodic noise remover.
Program:-
PRACTICAL:-18
P10EC949 Page:-
DIP Lab S.V.N.I.T.
AIM:- Write a Matlab code to blending two images in user defined manner.
Program:-
alpha=0.3;
h=(1-alpha).*f+alpha.*g;
subplot 223; imshow(uint8(h));
title('Blending For \alpha=0.3');
alpha=1.0;
h=(1-alpha).*f+alpha.*g;
subplot 224; imshow(uint8(h));
title('Blending For \alpha=1.0');
P10EC949 Page:-
DIP Lab S.V.N.I.T.
PRACTICAL:-19
AIM:- Write a Matlab code to perform Erosion, Dilation, Opening and Closing.
Program:-
f=imread('coins.png');
f=f(10+[1:180],20+[1:230]);
g=imerode(f,se); % Erosion
subplot 231; imshow(f);
title('Original Image');
h=imdilate(f,se); % Dilation
subplot 233; imshow(h);
title('After Dilation');
P10EC949 Page:-
DIP Lab S.V.N.I.T.
PRACTICAL:-20
AIM:- Write a Matlab code to generate different Walsh and Harr basis Images .
count=1;
for a=1:N,
for b=1:N,
subplot(N,N,count)
Im(:,:)=uint8(ff(a,b,:,:)); imshow(Im);
count=count+1;
end;
end;
end;
P10EC949 Page:-
DIP Lab S.V.N.I.T.
for a=1:N,
k(a)=a-1;
for b=1:n,
b1=b-1;
for c=1:N,
c1=c-1;
if (k(a)==(2^b1)+c1-1),
if(b1==0 && (c1==0 || c1==1))
p(a)=b1; q(a)=c1;
elseif(b1~=0 && (c1>=1 && c1<=2^b1))
p(a)=b1; q(a)=c1;
end;
end;
end;
end;
end; % to obtain k, p and q
for a=1:N,
for b=1:N,
z=(b-1)/N;
if(k(a)==0)
A(a,b)=1/sqrt(N);
elseif(z>=(q(a)-1)/(2^p(a)) && z<(q(a)-0.5)/(2^p(a)))
A(a,b)=(2^(p(a)/2))/sqrt(N);
elseif(z>=(q(a)-0.5)/(2^p(a)) && z<(q(a))/(2^p(a)))
A(a,b)=-(2^(p(a)/2))/sqrt(N);
else
A(a,b)=0;
end;
end;
end; % to obtain Harr Matrix h
display(A);
Output Matrix:-
A =
0.7071 -0.7071 0 0
0 0 0.7071 -0.7071
P10EC949 Page:-