0% found this document useful (0 votes)
4 views36 pages

PG CS

The document is a practical record for M.Sc. Computer Science students at SSM College of Arts & Science, detailing various digital image processing experiments conducted using MATLAB. It includes aims, algorithms, and sample programs for tasks such as RGB image quantization, histogram equalization, smoothing, edge detection, and image compression techniques. The record is intended for submission to Periyar University for practical examinations during the academic year 2023-2024.

Uploaded by

ssaravanangoki
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views36 pages

PG CS

The document is a practical record for M.Sc. Computer Science students at SSM College of Arts & Science, detailing various digital image processing experiments conducted using MATLAB. It includes aims, algorithms, and sample programs for tasks such as RGB image quantization, histogram equalization, smoothing, edge detection, and image compression techniques. The record is intended for submission to Periyar University for practical examinations during the academic year 2023-2024.

Uploaded by

ssaravanangoki
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SSM COLLEGE OF ARTS & SCIENCE

(An ISO 9001-2008 Certified Institution)


Affiliated to Periyar University
Komarapalayam – 638 183

[Link] COMPUTER SCIENCE


PRACTICAL RECORD

PRACTICAL – V 21PCSP05

DIGITAL IMAGE PROCESSING LAB

PERIYAR UNIVERSITY
SALEM – 636 011
NOVEMBER - 2023
SSM College of Arts & Science
(Affiliated to Periyar University)
KOMARAPALAYAM - 638 183

[Link]., COMPUTER SCIENCE


PRACTICAL RECORD

PRACTICAL – IV
DIGITAL IMAGE PROCESSING LAB
November -2023

Name : ______________________
Reg. No : ______________________

PERIYAR UNIVERSITY
SALEM – 636 011
SSM College of Arts & Science
(Affiliated to Periyar University)
KOMARAPALAYAM - 638 183

[Link]., COMPUTER SCIENCE


PRACTICAL – IV
DIGITAL IMAGE PROCESSING LAB
November -2023

Name : ______________________
Reg. No : ______________________

CERTIFICATE

Certified that this is a Bonafide record of work done by

__________________________ submitted to the Periyar University Practical

Examination during the academic year 2023 – 2024 held at SSM College of Arts

and Science on ____________________.

Subject-in-charge Head of the Department

Internal Examiner External Examiner


CONTENTS

Ex. PAGE
DATE TITLE SIGN
No. NO.
Ex No: 1 RGB Image Quantization with different number of
bits (1to8)
AIM:

To choose the grayscale image to RGB image the you will first have to grayscale (with
rgb2 gray() function). Display original image and the same image after their QUANTIZATION
withdifferent number of bits (1 to 8) using MATLAB.

ALGORITHM:

Step 1: Start the program.

Step 2: Open MATLAB, choose File menu and Select the M-File.

Step 3: Clear all the variables and the screen using clc.

Step 4: Write a code to read the RGB image in the Program.

Step 5: Convert the image from RGB to grayscale by rgb2 gray() function.

Step 6: Using Quantization, RGB image is quantized with different number of bits (1 to 8).

Step 7: Display the original image and display the quantized image after the process.

Step 8: Stop the process.

Page No. 1
PROGRAM:

RGB = imread('[Link]');
imshow(RGB)
I= rgb2gray(RGB);
figure
imshow(I)
threshRGB=multithresh(I,7);
threshForPlanes=zeros(3,7);
for i=1:3
threshForPLanes(i,:)= multithresh(I(:,:,i),7);
end
value=[0 threshRGB(2:end) 255];
quantRGB= imquantize(I,threshRGB,value);
quantPlane=zeros(size(I));
for i=1:3 value=[0 threshForPlanes(i,2:end) 255];
quantPlane(:,:,i)=imquantize(I(:,:,i),threshForPlanes(i,:),value);
end
quantPlane=unit8(quantPlane);
imshowpair(quantRGB,quantPlane,'montage')
axis offtitle('full RGB Image Quantization Plane-by-Plane Quantization')

Page No. 2
OUTPUT:

Result:

Thus the above program has been executed successfully.

Page No. 3
Ex no: 2 Histogram equalization on a color image
AIM:

To perform histogram equalization on color image using MATLAB.

ALGORITHM:

Step 1: Start the program.

Step 2: Open MATLAB, choose File menu and Select the M-File.

Step 3: Clear all the variables and the screen using clc.

Step 4: Read the RGB image in the Program.

Step5: Convert the RGB image to grayscale for further process.

Step 6: Map the histogram for the grayscale image.

Step 7: After Equalization, map the histogram for the equalized grayscale image.

Step 8: Finally display the mapped image.

Step 9: Stop the process.

Page No. 4
PROGRAM:

a=imread('[Link]');
b=rgb2gray(a);
subplot(2,2,1);
imshow(b);
title('grayscale image of original rgb image');

c=im2double(b);
subplot(2,2,2);
imhist(c);
title('histogram mapping od grayscale original image');

d=histeq(c);
subplot(2,2,3);
imshow(d);
title('grayscale original image after histogram equalisation');

subplot(2,2,4);
imhist(d);

Page No. 5
OUTPUT:

Result:

Thus the above program has been executed successfully.

Page No. 6
Ex no: 3 Using Spatial domain technique to perform
Smoothening
AIM:

To using spatial domain technique write a program in MATLAB to perform smoothing operation in a
image.

ALGORITHM:

Step 1: Start the program.

Step 2: Open MATLAB, choose File menu and Select the M-File.

Step 3: Clear all the variables and the screen using clc.

Step 4: Give the image in the coding in jpg to jpeg of digital image processing format.

Step 5: Give the sub plot of row and columns.

Step 6: Apply smoothing filters of linear filter Gaussian filter (2D filter).

Step7: Apply N-D filtering of multi-dimensional images using the subplots.

Step 8: Using the filters and then smooth the images.

Step 9: Sharpen the given images using the subplots.

Step 10: Save the program and run the program attach the image.

Page No. 7
PROGRAM:

a=imread('[Link]');
subplot(1,3,1);
imshow(a);
title('original image');
h=fspecial('gaussian');
b=imfilter(a,h);
subplot(1,3,2);
imshow(b);
title('smoothened image');
c=imsharpen(a);
subplot(1,3,3);

Page No. 8
OUTPUT:

Result:

Thus the above program has been executed successfully.

Page No. 9
Ex no: 4 I-D FIR filter to 2-D FIR filter using frequency
transformation method
AIM:

To write a MATLAB code to transform 1D FIR filter to 2D FIR filter using frequency
transformation method (FIR – Finite Impulse Response).

ALGORITHM:

Step 1: Start the program.

Step 2: Open MATLAB, choose File menu and Select the M-File.

Step 3: Clear all the variables and the screen using clc.

Step 4: Give the input image and frequency space.

Step 5: Create Fourier Transform of the input image.

Step 6: Using MATLAB library function FFt2 (2D Fast Fourier Transform)

Step 7: Calculating Euclidean distance D=(f1.^2+f2.^2).

Step 8: Using the subplot convert the images.

Step 9: Display the converted Image.

Step 10: Stop the process.

Page No. 10
PROGRAM:

input_image=imread('OIP [Link]');
[f1,f2]=freqspace(21,'meshgrid');
r=sqrt(f1.^2+f2.^2);
Hd=ones(21);
Hd((r<0.1)|(r>0.5))=0;
mesh(peaks)
colormap(parula(6))
mesh(f1,f2,Hd)
win=0.54-0.46*cos(2*pi*(0:20)/20);
figure
plot(linespacr(-1,1,21),win);
h=fwind1(Hd,win);
freqz2(h)
subplot(2,1,2),imshow(output_image);

Page No. 11
OUTPUT:

Result:

Thus the above program has been executed successfully.

Page No. 12
Ex no: 5 Sobel operator method using image
AIM:

To find the boundaries of object within an image by sobel operator method in MATLAB.

ALGORITHM:

Step 1: Start the program.

Step 2: Open MATLAB, choose File menu and Select the M-File.

Step 3: Clear all the variables and the screen using clc.

Step 4: Give the image in the coding in jpg or jpeg of MATLAB format.

Step 5: In the program we need to convert RGB to gray image.

Step 6: Apply the sobel edge detector to the unfiltered input image.

Step 7: Display the filtered image.

Step 8: Stop the process.

Page No. 13
PROGRAM:

a=imread('[Link]');
b=rgb2gray(a);
subplot(2,2,1);
imshow(a);
title('Original Image');
c1=edge(b,'sobel');
subplot(2,2,2);
imshow(c1);
title('Sobel Operator');
c2=edge(b,'prewitt');
subplot(2,2,2);
imshow(c2);
title('Prewitt Operator');
c3=edge(b,'roberts');
subplot(2,2,4);
imshow(c3);
title('Roberts Operator')

Page No. 14
OUTPUT:

Result:

Thus the above program has been executed successfully.

Page No. 15
Ex no: 6 compare the image using canny and Prewitt
methods
AIM:

To write a MATLAB program to detect the edge within the image and compare the results of
both canny and prewitt method.

ALGORITHM:

Step 1: Start the program.

Step 2: Open MATLAB, choose File menu and Select the M-File.

Step 3: Clear all the variables and the screen using clc.

Step 4: Apply the Canny Edge detector to the given image.

Step 5: Apply the Prewitt operator to the given image.

Step 6: Compare the image and display it.

Step 7: Stop the process.

Page No. 16
PROGRAM:

I=imread('[Link]');
imshow(I)
BW1=edge(I,'Canny');
BW2=edge(I,'Prewitt');
imshowpair(BW1,BW2,'montage')

Page No. 17
OUTPUT:

Result:

Thus the above program has been executed successfully.

Page No. 18
Ex no: 7 Compress an image using Huffman coding method
AIM:

To write a program to compress an image using Huffman Coding method in MATLAB.

ALGORITHM:

Step 1: Start the program.

Step 2: Open MATLAB, choose File menu and Select the M-File.

Step 3: Clear all the variables and the screen using clc.

Step 4: Read the image and convert an image to grayscale.

Step 5: To find the probability of the variables compute the cumulative probability and pro array.

Step 6: Import Huffman code dictionary to encode and decode it.

Step 7: To Converting dhsig 1 double to dhsig uint8.

Step 8: To convert vector into array

arr_col=arr_col+1;

Vec_si=vec_si+1;

Step 9: Convert image from grayscale to rgb and display it.

Step 10: Stop the process.

Page No. 19
PROGRAM:

clear all
clc
a=imread('[Link]');
figure,imshow(a)
I=rgb2gray(a);
[m,n]=size(I);
Toatalcount=m*n;
cnt=1;
sigma=0;
for i=0:255
k=I==i;
count(cnt)=sum(k(:))
pro(cnt)=count(cnt)/Toatalcount;
sigma=sigma+pro(cnt);
compro(cnt)=sigma;
cnt=cnt+1;
end;
symbols=[0:255];
dict=huffmandict([Link]);
vec_size=1;
for p=1:m
for q=1:n
newvec(vec_size)=I(p,q);
vec_size=vec_size+1;
end
end
hcode=huffmanenco(newvec,dict);
dhsig1=huffmandeco(hcode,dict);
dhsig=uint8(dhsig1);
dec_row=sqrt(length(dhsig));
dec_col=dec_row;
arr_row=1;
arr_col=1;
vec_si=1;
for x=1:m
for y=1:n
back(x,y)=dhsig(vec_si);
arr_col=arr_col+1;
vec_si=vec_si+1;
end
arr_row=arr_row+1;
end
[deco,map]=gray2ind(back,256);
RGB=ind2rgb(deco,map);
imwrite(RGB,'[Link]');

Page No. 20
OUTPUT:

Result:

Thus the above program has been executed successfully.

Page No. 21
Ex No: 8 Compress an image using cosine transformation
method
AIM:

To implement discrete Cosine Transformation method to compress an image using


MATLAB.

ALGORITHM:

Step 1: Start the program.

Step 2: Open MATLAB, choose File menu and Select the M-File.

Step 3: Clear all the variables and the screen using clc.

Step 4: To check if it is RGB or grayscale if it is RGB convert to grayscale.

Step 5: To compress the input image divide the image into 8*8 block.

Step 6: To remove the coefficient in zig-zag design a filter.

Step 7: To cut the coefficients use the filter filt.

Step 8: To decompress compute PSNR.

Step 9: Find and clear error in pixel values and display the compressed image.

Step 10: Stop the process.

Page No. 22
PROGRAM:

disp('Image compression by using DCT blackproc function');


tic;
im=imread('OIP [Link]');
if(size(im,3)>1)
inim=double(rgb2gray(im));
disp('The given image is RGB. It is converted to grayscale');
[r c]=size(inim);
dim=strcat('image size',int2str(r),'X',int2str(c),'pixels');
disp(dim);
end
inim1=uint8(inim);

figure(1)
imshow(inim1);
title 'Original Image'
blksize=8;
dctcoef=blockproc(inim,[blksize,blksize],@(block_struct)dct2(block_struct.data));
manner
filt28=[1 1 1 1 1 1 1 0;
1 1 1 1 1 1 1 0 0;
1 1 1 1 1 1 0 0 0;
1 1 1 1 1 0 0 0 0;
1 1 1 1 0 0 0 0 0;
1 1 1 0 0 0 0 0 0;
1 1 0 0 0 0 0 0 0;
1 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0];
filt10=[1 1 1 1 0 0 0 0;
1 1 1 0 0 0 0 0;
1 1 0 0 0 0 0 0;
1 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0];
filt6=[1 1 1 0 0 0 0 0;
1 1 0 0 0 0 0 0;
1 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0];
filt=filt10;
required
cuttcoef=blockproc(dctcoef,[blksize,blksize],@(blcok_struct)block_struct.data.*filt);

Page No. 23
decompim=blockproc(cuttcoef,[blksize,blksize],@(block_struct)idct2(block_struct.data));
figure(2);
imshow(decompim,[]);
title 'Reconstructed Image';
DIF=imsubtract(inim,decompim);
mse=mean(mean(DIF.*DIF));
rmse=sqrt(mse);
psnr=20*log(255/rmse);
disp('PSNR');
disp(psnr);
toc

Page No. 24
OUTPUT:

Result:

Thus the above program has been executed successfully.

Page No. 25
Ex no: 9 Legibility of text using thresholding technique
AIM:

To write a MATLAB code for Image segmentation to convert binary image to improve the
legibility text using threasholding technique.

ALGORITHM:

Step 1: Start the program.

Step 2: Open MATLAB, choose File menu and Select the M-File.

Step 3: Clear all the variables and the screen using clc.

Step 4: Read the grayscale image into the workspace.

Step 5: Calculate a threashold using graythresh . The threashold is normalized to the range [0,1].

Step 6: Convert the image into binary image using the threshold image.

Step 7: Display the original image.

Step 8: Stop the process.

Page No. 26
PROGRAM:
I=imread('[Link]');
level=graythresh(I)
level=0.4941
BW=im2bw(I,level);
imshow(BW)

Page No. 27
OUTPUT:

Result:

Thus the above program has been executed successfully.

Page No. 28
Ex no: 10 Image using marker-controlled watershed
Segmentation
AIM:

To compute the watershed transform of the segmentation function in an image at foreground


and background marker pixels using marker-controlled watershed segmentation in MATLAB.

ALGORITHM:

Step 1: Start the program.

Step 2: Open MATLAB, choose File menu and Select the M-File.

Step 3: Clear all the variables and the screen using clc.

Step 4: Read the color image and convert it to grayscale.

Step 5: Use the gradient magnitude as a segmentation function.

Step 6: Mark the foreground object.

Step 7: Compute background markers.

Step 8: Compute the watershed transform of the segmentation function.

Step 9: Display the transformed image.

Step 10: Stop the process.

Page No. 29
PROGRAM:

rgb=imread('OIP [Link]');
I=rgb2gray(rgb);
imshow(I)
text(732,501,'Image courtesy of Cond','Fontsize',7,'Horizontal Alignment','right')
hy=fspecial('sobel');
hx=hy;
Iy=imfilter(double(I),hy,'replicate');
Ix=imfilter(double(I),hx,'replicate');
gradmag=sqrt(Ix.^2+Iy.^2);
figure
imshow(gradmag,[]),title('gradmag')
L=watershed(gradmag);
Lrgb=label2rgb(L);
figure
imshow(Lrgb),title('Lrgb')
se=strel('disk',20);
Io=imopen(I,se);
figure
imshow(Io),title('Io')
Ie=imerode(I,se);
Iobr=imreconstruct(Ie,I);
figure
imshow(Iobr),title(Iobr')
Ioc=imclose(Io,se);
figure
imshow(Ioc),title('Ioc')
Iobrd=imdilate(Lobr,se);
Iobrcbr=imreconstruct(imcomplement(Iobrd),imcomplement(IIobr));
Iobrcbr=imcomplement(Iobrcbr);
figure
imshow(Iobrcbr),title('Iobrcbr')
fgm=imregionalmax(Iobrcbr);
figure
imshow(fgm),title('fgm')
I2=I;
I2(fgm)=255;
figure
imshow(I2),title('fgm superimposed on original image')
se2=strel(ones(5,5));
fgm2=imclose(fgm,se2);
fgm3=imerode(fgm2,se2);
fgm4=bwareaopen(fgm3,20);
I3=1;
I3(fgm4)=255;
figure
imshow(I3)

Page No. 30
title('fgm4 superimposed on original image')
bw=im2bw(Iobrcbr,graythresh(Iobrcbr));
figure
imshow(bw),title('bw')
D=bwdist(bw);
Dl=watershed(D);
bdm=DL==0;
figure
imshow(bgm),title('bgm')
gradmag2=imimposemin(gradmag,bgm|fgm4);
L=watershed(gradmag2);
I4=I;
I4(imdilate(L==0,ones(3,3))|bgm|fgm4)=255;
figure
imshow(I4)
title('Markers and object boundaries superimposed on original image')
Lrgb=label2rgb(L,'jet','w','shuffle');
figure
imshow(Lrgb)
title('Lrgb')
figure
imshow(I),hold on
himage=imshow(Lrgb);
set(himage,'AlphaData',0.3);
title('Lrgb superimposed transparently on original image')

Page No. 31
OUTPUT:

Result:

Thus the above program has been executed successfully.

Page No. 32

You might also like