Digital Image Processing Lab Manual
Digital Image Processing Lab Manual
Digital Image Processing Lab Manual
%Red Component
r=i(:,:,1);
subplot(3,2,2); imshow(r);title('Red Component');
%Green Component
g=i(:,:,2);
subplot(3,2,3); imshow(g); title('Green Component');
%Blue Component
b=i(:,:,3);
subplot(3,2,4); imshow(b); title('Blue Component');
% Display color Image, find its complement and convert to gray scale
I=imread('cancercell.jpg');
subplot(2,2,1); imshow(I); subimage(I); title('Color Image');
c=imcomplement(I);
subplot(2,2,2); imshow(c); subimage(c); title('Complement of color Image');
r=rgb2gray(I);
subplot(2,2,3); imshow(r); subimage(r); title('Gray scale of color Image');
a=magic(5);
disp(‘a=’); disp(a);
b=input('Enter the row < size of the Matrix');
c=input(' Enter the Column < size of matrix');
disp(‘Element’); disp(a(b,c));
% 4 Point Neighbour
N4=[a(b+1,c), a(b-1,c), a(b,c+1), a(b,c-1)];
disp(‘N4=’); disp(N4);
%8 Point Neighbour
N8=[a(b+1,c), a(b-1,c), a(b,c+1), a(b,c-1), a(b+1,c+1), a(b+1,c-1), a(b-1,c-1), a(b-1,c+1)];
disp(‘N8=’); disp(N8);
%Diagonal Neighbour
ND=[ a(b+1,c+1), a(b+1,c-1), a(b-1,c-1), a(b-1,c+1)];
disp(‘ND=’); disp(ND);
Output
a=
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
% Scaling (Resize)
I=imread('earcell.jpg');
subplot(2,2,1); subimage(I); title('Original Image');
% Rotation
K=imrotate(j,60);
subplot(2,2,3); imshow(K); title('Rotated Image 60deg');
R=imrotate(j,45);
subplot(2,2,4); imshow(R); title('Rotated Image 45deg');
7
%Display the color image and its Resized images by different methods
% Image Enhancement
I=imread('cancercell.jpg');
subplot(4,2,1); imshow(I); title('Original Image');
g=rgb2gray(I);
subplot(4,2,5); imshow(g); title('Gray Image');
J=imadjust(g,[0.3 0.7],[]);
subplot(4,2,3); imshow(J); title('Enhanced Image');
m=histeq(g);
subplot(4,2,6); imshow(m); title('Equalized Image');
subplot(4,2,8); imhist(m); title('Histogram of Equalized Image');
9
i=imread('earcell.jpg');
b0=double(bitget(i,1));
b1=double(bitget(i,2));
b2=double(bitget(i,3));
b3=double(bitget(i,4));
b4=double(bitget(i,5));
b5=double(bitget(i,6));
b6=double(bitget(i,7));
b7=double(bitget(i,8));
subplot(3,3,1);imshow(i);title('Original Image');
subplot(3,3,2);subimage(b0);title('BIT PLANE 0');
subplot(3,3,3);subimage(b1);title('BIT PLANE 1');
subplot(3,3,4);subimage(b2);title('BIT PLANE 2');
subplot(3,3,5);subimage(b3);title('BIT PLANE 3');
subplot(3,3,6);subimage(b4);title('BIT PLANE 4');
subplot(3,3,7);subimage(b5);title('BIT PLANE 5');
subplot(3,3,8);subimage(b6);title('BIT PLANE 6');
subplot(3,3,9);subimage(b7);title('BIT PLANE 7');
10
l=im2double(imread('cancercell.jpg'));
f1=fft(l);
f2=fftshift(f1);
subplot(2,2,1); imshow(abs(f1)); title('Frequency Spectrum');
subplot(2,2,2); imshow(abs(f2)); title('Centered Spectrum');
f3=log(1+abs(f2));
subplot(2,2,3); imshow(f3); title('log(1+abs(f2))');
l=fft2(f1);
l1=real(l);
subplot(2,2,4); imshow(l1);title(' 2-D FFT');
11
i=imread('cancercell.jpg');
subplot(2,2,1); imshow(i);title('Original Image');
g=rgb2gray(i);
subplot(2,2,2); imshow(g);title('Gray Image');
c=imcrop(g);
subplot(2,2,3); imshow(c);title('Cropped Image');
m=mean2(c);disp('m'); disp(m);
s=std2(c); disp('s'); disp(s);
figure,
k=(checkerboard>0.8);
subplot(2,1,1); imshow(k); title('Image1');
k1=(checkerboard>0.5);
subplot(2,1,2); imshow(k1); title('Image2');
r=corr2(k,k1);
disp('r');disp(r);
m
74.5173
s
44.2327
r
0.5774
12
13
9. Implementation of image sharpening filters and Edge Detection using Gradient Filters
i=imread('cancercell.jpg');
subplot(4,2,1); imshow(i);
title('Original Image');
g=rgb2gray(i);
subplot(4,2,2); imshow(g); title('Gray Image');
f=fspecial('laplacian',0.05);
im=imfilter(g,f);
subplot(4,2,3); imshow(im); title('Laplacian ');
s=edge(g, 'sobel');
subplot(4,2,4); imshow(s); title('Sobel');
p=edge(g, 'prewitt');
subplot(4,2,5); imshow(p); title('Prewitt');
r=edge(g, 'roberts');
subplot(4,2,6); imshow(r); title('Roberts');
[BW,thresh,gv,gh]=edge(g,'sobel',[],'horizontal');
[BW1,thresh1,gv1,gh1]=edge(g,'sobel',[],'vertical');
i=imread('earcell.jpg');
subplot(3,2,1);imshow(i); title(‘Original Image’);
l=im2double(i);
level=graythresh(l);
BW = im2bw(l,level);
subplot(3,2,2); imshow(BW); title('Image graythresh');
level1=0.2*BW;
subplot(3,2,3); imshow(level1); title('0.2 Slice');
level2=0.4*BW;
subplot(3,2,4); imshow(level2);title('0.4 Slice');
level3=0.6*BW;
subplot(3,2,5); imshow(level3);title('0.6 Slice');
level4=0.8*BW;
subplot(3,2,6); imshow(level4); title('0.8 Slice');
20
i= imread('cancercell.jpg');
g=rgb2gray(i);
subplot(2,2,1); imshow(i); title('Original Image');
subplot(2,2,2); imshow(g); title('Gray Image');
c=edge(g,'canny');
subplot(2,2,3); imshow(c); title('Canny output');