Digital Image Processing File
Digital Image Processing File
SYLLABUS
FOR
Course Outcomes: At the end of this course students will demonstrate the ability to:
1. Describe the concept and need for image processing.
2. Implement the various techniques for image enhancement and restoration both in spatial and frequency domains.
3. Interpret the various types of image transforms and their properties.
4. Distinguish between lossless and lossy image compression algorithms and examine their performances in spatial
and frequency domains.
5. Examine the various image segmentation techniques.
KEC-751A Digital Image Processing Lab 0L:0T:2P 1 Credit
Course Outcomes: At the end of this course students will demonstrate the ability to:
1. Explain image processing operations using MATLAB tool.
2. Evaluate the appropriate methods for image enhancement and image restoration.
3. Formulate spatial and frequency domain filters to obtain better quality image.
4. Select various attributes of image such as texture and edges from the image.
5. Design and develop the applications of transforms such as DCT and wavelet.
AIM:
APPARATUS REQUIRED:
INTRODUCTION TO MATLAB:
AIM:
Write a MATLAB program to learn the basic image processing operations.
APPARATUS REQUIRED:
RESULT:
Thus the MATLAB program Reading images, Image display, Four image in one frame , Image information
, Writing image , Image quality to reduce the resolution of the image ,Histogram ,Image sharpening using
MATLAB function written and the results were plotted.
EXPERIMENT NO: 3
AIM:
Write a MATLAB program for geometric transformation.
APPARATUS REQUIRED:
HARDWARE: Personal Computer
SOFTWARE: MATLAB 7.8
PROCEDURE:
1. Start the MATLAB program.
2. Open new M-file
3. Type the program
4. Save in current directory
5. Compile and Run the program
6. If any error occurs in the program correct the error and run it again
7. For the output see command window\ Figure window
8. Stop the program.
I=imread('bird.jpg');
% 2-D affine transformation
tform=affine2d([1 0 0;0.5 1 0;0 0 1]);
J=imwarp(I,tform);
subplot(2,3,1),imshowpair(I,J,"montage");title('2-D affine transformation')
% Rotated image 10 deg
x=10;
tform1=affine2d([cosd(x) -sind(x) 0;sind(x) cosd(x) 0;0 0 1]);
K=imwarp(I,tform1);
subplot(2,3,2),imshowpair(I,K,"montage");title('Rotated image 10 deg')
% translated image
L=imtranslate(I,[330,-180],'FillValues',255);
subplot(2,3,3),imshowpair(I,L,"montage"), title('Translated Image');
% Scaling iamge
magnifiaction=0.5;
M=imresize(I,magnifiaction);
subplot(2,3,4),imshowpair(I,M,method="montage");title('Scaling image');
% Rotated image 45 deg
N=imrotate(I,45,"bilinear");
subplot(2,3,5),imshowpair(I,N,method="montage"),title('Rotated image 45
deg');
RESULT:
Thus the MATLAB program written and the results were plotted.
EXPERIMENT NO: 4
AIM:
Write a MATLAB program for image enhancement using Histogram equalization.
APPARATUS REQUIRED:
HARDWARE: Personal Computer
SOFTWARE: MATLAB 7.8
PROCEDURE:
1. Start the MATLAB program.
2. Open new M-file
3. Type the program
4. Save in current directory
5. Compile and Run the program
6. If any error occurs in the program correct the error and run it again
7. For the output see command window\ Figure window
8. Stop the program.
I=imread('nature.jpg');
Ih=histeq(I);
subplot(2,2,1),imshow(I),title('Original Image');
subplot(2,2,2),imshow(Ih),title(' Histogram Equalized Image');
subplot(2,2,3),imhist(I),title('Histogram of Original Image');
subplot(2,2,4),imhist(Ih),title('Histogram of Equalized Image');
Thus the MATLAB program written and the results were plotted.
EXPERIMENT NO: 5
AIM:
Write a MATLAB program to perform smoothing or averaging filter in spatial domain.
APPARATUS REQUIRED:
HARDWARE: Personal Computer
SOFTWARE: MATLAB 7.8
PROCEDURE:
1. Start the MATLAB program.
2. Open new M-file
3. Type the program
4. Save in current directory
5. Compile and Run the program
6. If any error occurs in the program correct the error and run it again
7. For the output see command window\ Figure window
8. Stop the program.
clc
clear all
close all
%Reading input image for filtering
A=imread('bird.jpg');
%Addition of noise to the input images
B=imnoise(A,'salt & pepper');
C=imnoise(A,'gaussian');
D=imnoise(A,'speckle');
% Defining 3x3 and 5x5 kernel
h1=1/9*ones(3,3);
h2=1/25*ones(5,5);
%Attempting to recover the image
B1=uint8(convn(double(B),h1,'same'));
B2=uint8(convn(double(B),h2,'same'));
C1=uint8(convn(double(C),h1,'same'));
C2=uint8(convn(double(C),h2,'same'));
D1=uint8(convn(double(D),h1,'same'));
D2=uint8(convn(double(D),h2,'same'));
% Display the images
subplot(3,3,1),imshowpair(A,B,"montage"),title('Noisy Image of salt &
pepper');
subplot(3,3,2),imshowpair(B,B1,"montage"),title(' Use of 3x3 Averaging
filter');
subplot(3,3,3),imshowpair(A,B2,"montage"),title('Use of 5x5 Averaging
filter');
subplot(3,3,4),imshowpair(A,C,"montage"),title('Noisy Image of Gaussian');
subplot(3,3,5),imshowpair(C,C1,"montage"),title('Use of 3x3 Averaging
filter');
subplot(3,3,6),imshowpair(C,C2,"montage"),title('Use of 5x5 Averaging
filter');
subplot(3,3,7),imshowpair(A,D,"montage"),title('Noisy Image of speckle');
subplot(3,3,8),imshowpair(D,D1,"montage"),title('Use of 3x3 Averaging
filter');
subplot(3,3,9),imshowpair(D,D2,"montage"),title('Use of 5x5 Averaging
filter');
RESULT:
Thus the MATLAB program written and the results were plotted.
EXPERIMENT NO: 6
AIM:
Write a MATLAB program to perform smoothing or averaging filter in frequency domain.
APPARATUS REQUIRED:
HARDWARE: Personal Computer
SOFTWARE: MATLAB 7.8
PROCEDURE:
1. Start the MATLAB program.
2. Open new M-file
3. Type the program
4. Save in current directory
5. Compile and Run the program
6. If any error occurs in the program correct the error and run it again
7. For the output see command window\ Figure window
8. Stop the program.
PROGRAM:
RESULT:
Thus, the MATLAB program written and the results were plotted.
EXPERIMENT NO: 7
AIM:
Write a MATLAB program for image restoration.
APPARATUS REQUIRED:
HARDWARE: Personal Computer
SOFTWARE: MATLAB 7.8
PROCEDURE:
1. Start the MATLAB program.
2. Open new M-file
3. Type the program
4. Save in current directory
5. Compile and Run the program
6. If any error occurs in the program correct the error and run it again
7. For the output see command window\ Figure window
8. Stop the program.
PROGRAM:
A=imread('bird1.jpg');
subplot(2,3,1),imshow(uint8(A)),title('Original iamge');
A=double(rgb2gray(A));
[M,N] = size(A);
% degradation function
h = ones(11,11)/121;
% transformation to frequency domain
freq_a = fft2(A);
freq_h = fft2(h,M,N);
% degraded iamge
B = real(ifft2(freq_h.*freq_a))+10*randn(M,N);
% inverse filtering for image restoration
freq_b = fft2(B);
powfreq_a = freq_a.^2/(M*N);
alpha = 0.5;
sigma = sqrt(4*10^(-7));
freq_g = ((freq_h.')').*abs(powfreq_a).....
./(abs(freq_h.^2).*abs(powfreq_a)+alpha*sigma^2);
Res_freq_a = freq_g.*freq_b;
% Restored iamge in spatial domain
Res_a = real(ifft2(Res_freq_a));
% display of output images
subplot(2,3,2),imshow(uint8(B)),title('Degraded image');
subplot(2,3,3),imshow(uint8(Res_a)),title('Restored image after inverse
filtering');
RESULT:
Thus, the MATLAB program written and the results were plotted.
EXPERIMENT NO: 8
AIM:
Write a MATLAB program of sharpening of image using gradient mask.
APPARATUS REQUIRED:
HARDWARE: Personal Computer
SOFTWARE: MATLAB 7.8
PROCEDURE:
1. Start the MATLAB program.
2. Open new M-file
3. Type the program
4. Save in current directory
5. Compile and Run the program
6. If any error occurs in the program correct the error and run it again
7. For the output see command window\ Figure window
8. Stop the program.
% unsharp masking
H=fspecial('unsharp');
B=imfilter(A,H);
Thus, the MATLAB program written and the results were plotted.
EXPERIMENT NO: 9
AIM:
Write a MATLAB program for performing morphological operations on the image.
APPARATUS REQUIRED:
HARDWARE: Personal Computer
SOFTWARE: MATLAB 7.8
PROCEDURE:
1. Start the MATLAB program.
2. Open new M-file
3. Type the program
4. Save in current directory
5. Compile and Run the program
6. If any error occurs in the program correct the error and run it again
7. For the output see command window\ Figure window
8. Stop the program.
Thus the MATLAB program written and the results were plotted.
EXPERIMENT NO: 10
AIM:
Write a MATLAB program to fill the region of interest of the image.
APPARATUS REQUIRED:
HARDWARE: Personal Computer
SOFTWARE: MATLAB 7.8
PROCEDURE:
1. Start the MATLAB program.
2. Open new M-file
3. Type the program
4. Save in current directory
5. Compile and Run the program
6. If any error occurs in the program correct the error and run it again
7. For the output see command window\ Figure window
8. Stop the program.
Thus, the MATLAB program written and the results were plotted.
EXPERIMENT NO: 11
AIM:
Write a MATLAB program for edge detection of an image.
APPARATUS REQUIRED:
HARDWARE: Personal Computer
SOFTWARE: MATLAB 7.8
PROCEDURE:
1. Start the MATLAB program.
2. Open new M-file
3. Type the program
4. Save in current directory
5. Compile and Run the program
6. If any error occurs in the program correct the error and run it again
7. For the output see command window\ Figure window
8. Stop the program.
Thus, the MATLAB program written and the results were plotted.