0% found this document useful (0 votes)
429 views

BM2406 Digital Image Processing Lab Manual

Lab manual for B.E. Biomedical Engineering BM2406 Digital Image Processing Lab Manual of Anna University

Uploaded by

Deepak Dennison
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
429 views

BM2406 Digital Image Processing Lab Manual

Lab manual for B.E. Biomedical Engineering BM2406 Digital Image Processing Lab Manual of Anna University

Uploaded by

Deepak Dennison
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 24

EX NO: 9

HISTOGRAM EQUALIZATION WITHOUT USING INBUILT FUNCTION


clear;
clc;
I=imread('cameraman.tif');
I=double(I);
maximum_value=max((max(I)));
[row col]=size(I);
c=row*col;
h=zeros(1,300);
z=zeros(1,300);
for n=1:row
for m=1:col
if I(n,m) == 0
I(n,m)=1;
end
end
end
for n=1:row
for m=1:col
t = I(n,m);
h(t) = h(t) + 1;
end
end
pdf = h/c;
cdf(1) = pdf(1);
for x=2:maximum_value
cdf(x) = pdf(x) + cdf(x-1);
end
new = round(cdf * maximum_value);
new= new + 1;
for p=1:row
for q=1:col
temp=I(p,q);
b(p,q)=new(temp);
t=b(p,q);
z(t)=z(t)+1;
end
end
b=b-1;
subplot(2,2,1);
imshow(uint8(I)) , title(' Image1');
subplot(2,2,2), bar(h) , title('Histogram of the Original Image');
subplot(2,2,3), imshow(uint8(b)) , title('Image2');

subplot(2,2,4), bar(z) , title('Histogram Equalisation of image2');


HISTOGRAM EQUALIZATION USING INBUILT FUNCTION
img1=imread('cameraman.tif');
equalised=histeq(img1);
subplot(221);imshow(img1);title('Original Image');
subplot(222);imhist(img1);title('Original Image Histogram');
subplot(223);imshow(equalised);title('Equalised Image');
subplot(224);imhist(equalised);title('Equalised Image Histogram');

OUTPUT
HISTOGRAM EQUALIZATION WITHOUT INBUILT FUNCTION

HISTOGRAM EQUALIZATION WITH INBUILT FUNCTION

EX 10
EDGE DETECTION

img1=imread('cameraman.tif');
img2=edge(img1,'canny');
img3=edge(img1,'log');
img4=edge(img1,'prewitt');
img5=edge(img1,'roberts');
img6=edge(img1,'sobel');
img7=edge(img1,'zerocross');
subplot(421);
imshow(img1);
title('original');
subplot(422);
imshow(img2);
title('canny');
subplot(423);
imshow(img3);
title('log');
subplot(424);
imshow(img4);
title('prewitt');
subplot(425);
imshow(img5);
title('roberts');
subplot(426);
imshow(img6);
title('sobel');
subplot(427);
imshow(img7);
title('zerocross');

OUTPUT:
EDGE DETECTION

EX 11
FREQUENCY DOMAIN FILTERS
BUTTERWORTH LOWPASS FILTER

clear;
clc;
img=imread('Coins.png');
[X,Y]=size(img);
N=input('Order of Filter=');
x=ceil(X/2);
y=ceil(Y/2);
rad=26;
for i=1:X
for j=1:Y
d(i,j)=sqrt((i-x).^2+(j-y).^2);
h(i,j)=1/(1+((d(i,j))/rad).^(2*N));
end
end
fft1=fftshift(fft2(img));
fil=h.*fft1;
fin=ifft2(fil);
fin1=uint8(fin);
subplot(221);
imshow(img);
title('Original');
subplot(222);
imshow(fin1);
title('After LPF');
subplot(223);
surf(h);
title('LPF in 3D');
subplot(224);
imshow(h);
title('LPF as Image');
BUTTERWORTH HIGH PASS FILTER
clear;
clc;
img=imread('Coins.png');
[X,Y]=size(img);
N=input('Order of Filter=');
x=ceil(X/2);
y=ceil(Y/2);
rad=26;
for i=1:X
for j=1:Y
d(i,j)=sqrt((i-x).^2+(j-y).^2);
h(i,j)=1-(1/(1+((d(i,j))/rad).^(2*N)));

end
end
fft1=fftshift(fft2(img));
fil=h.*fft1;
fin=ifft2(fil);
fin1=uint8(fin);
subplot(221);
imshow(img);
title('Original');
subplot(222);
imshow(fin1);
title('After HPF');
subplot(223);
surf(h);
title('HPF in 3D');
subplot(224);
imshow(h);
title('HPF as Image');
IDEAL LOW PASS FILTER
clear;
clc;
img=imread('Coins.png');
[X,Y]=size(img);
N=input('Order of Filter=');
x=ceil(X/2);
y=ceil(Y/2);
rad=26;
for i=1:X
for j=1:Y
d(i,j)=sqrt((i-x).^2+(j-y).^2);
if d(i,j)<=rad
h(i,j)=1;
else
h(i,j)=0;
end
end
end
fft1=fftshift(fft2(img));
fil=h.*fft1;
fin=ifft2(fil);
fin1=uint8(fin);
subplot(221);

imshow(img);
title('Original');
subplot(222);
imshow(fin1);
title('After Ideal LPF');
subplot(223);
surf(h);
title('Ideal LPF in 3D');
subplot(224);
imshow(h);
title('Ideal LPF as Image');
IDEAL HIGH PASS FILTER
clear;
clc;
img=imread('Coins.png');
[X,Y]=size(img);
N=input('Order of Filter=');
x=ceil(X/2);
y=ceil(Y/2);
rad=26;
for i=1:X
for j=1:Y
d(i,j)=sqrt((i-x).^2+(j-y).^2);
if d(i,j)<=rad
h(i,j)=0;
else
h(i,j)=1;
end
end
end
fft1=fftshift(fft2(img));
fil=h.*fft1;
fin=ifft2(fil);
fin1=uint8(fin);
subplot(221);
imshow(img);
title('Original');
subplot(222);
imshow(fin1);
title('After Ideal HPF');
subplot(223);
surf(h);

title('Ideal HPF in 3D');


subplot(224);
imshow(h);
title('Ideal HPF as Image');
GAUSSIAN LOW PASS FILTER:
clear;
clc;
img=imread('Coins.png');
[X,Y]=size(img);
N=input('Order of Filter=');
x=ceil(X/2);
y=ceil(Y/2);
rad=26;
for i=1:X
for j=1:Y
d(i,j)=sqrt((i-x).^2+(j-y).^2);
h(i,j)=exp(-(d(i,j).^2)/(2*((rad).^2)));
end
end
fft1=fftshift(fft2(img));
fil=h.*fft1;
fin=ifft2(fil);
fin1=uint8(fin);
subplot(221);
imshow(img);
title('Original');
subplot(222);
imshow(fin1);
title('After Gaussian LPF');
subplot(223);
surf(h);
title('Gaussian LPF in 3D');
subplot(224);
imshow(h);
title('Gaussian LPF as Image');
GAUSSIAN HIGH PASS FILTER:
clear;
clc;
img=imread('Coins.png');
[X,Y]=size(img);
N=input('Order of Filter=');
x=ceil(X/2);

y=ceil(Y/2);
rad=26;
for i=1:X
for j=1:Y
d(i,j)=sqrt((i-x).^2+(j-y).^2);
h(i,j)=1-exp(-(d(i,j).^2)/(2*((rad).^2)));
end
end
fft1=fftshift(fft2(img));
fil=h.*fft1;
fin=ifft2(fil);
fin1=uint8(fin);
subplot(221);
imshow(img);
title('Original');
subplot(222);
imshow(fin1);
title('After Gaussian HPF');
subplot(223);
surf(h);
title('Gaussian HPF in 3D');
subplot(224);
imshow(h);
title('Gaussian HPF as Image');

OUTPUT:
BUTTERWORTH LOWPASS FILTER

BUTTERWORTH HIGHPASS FILTER

IDEAL LOWPASS FILTER

IDEAL HIGHPASS FILTER

GAUSSIAN LOWPASS FILTER

GAUSSIAN LOWPASS FILTER

EX 12

DISCRETE WAVELET TRANSFORM


USING HAAR
clc;
clear;
img1=imread('pout.tif');
[p,q,r,s]=dwt2(img1,'haar');
wav1=[p,q;r,s];
[p1,q1,r1,s1]=dwt2(p,'haar');
wav2=[p1,q1;r1,s1];
wav3=idwt2(p1,q1,r1,s1,'haar');
subplot(221),imshow(img1),title('Original');
subplot(222),imshow(wav1,[]),title('DWT Decimation');
subplot(223),imshow(wav2,[]),title('DWT Decimation');
subplot(224),imshow(wav3,[]),title('Reconstructed');
USING DOUBECHIES
clc;
clear;
img1=imread('pout.tif');
[p,q,r,s]=dwt2(img1,'db3');
wav1=[p,q;r,s];
[p1,q1,r1,s1]=dwt2(p,'db3');
wav2=[p1,q1;r1,s1];
wav3=idwt2(p1,q1,r1,s1,'db3');
subplot(221),imshow(img1),title('Original');
subplot(222),imshow(wav1,[]),title('Daubechies DWT Decimation');
subplot(223),imshow(wav2,[]),title('Daubechies DWT Decimation');
subplot(224),imshow(wav3,[]),title('Daubechies Reconstructed');
USING BIORTHOGONAL
clc;
clear;
img1=imread('pout.tif');
[p,q,r,s]=dwt2(img1,'bior3.5');
wav1=[p,q;r,s];
[p1,q1,r1,s1]=dwt2(p,'bior3.5');
wav2=[p1,q1;r1,s1];
wav3=idwt2(p1,q1,r1,s1,'bior3.5');
subplot(221),imshow(img1),title('Original');
subplot(222),imshow(wav1,[]),title('Biorthogonal DWT Decimation');
subplot(223),imshow(wav2,[]),title('Biorthogonal DWT Decimation');
subplot(224),imshow(wav3,[]),title('Biorthogonal Reconstructed');
OUTPUT
USING HAAR

USING DOUBECHIES

USING BIORTHOGONAL

EX 13
WATERSHED TRANSFORM

clc;
clear;
img1=checkerboard(40);
img2=imnoise(img1,'salt & pepper',0.1);
wa1=watershed_old(img1,6);
wa2=watershed_old(img2,6);
subplot(221),imshow(img1),title('Image 1');
subplot(222),imshow(img2),title('Image 2');
subplot(223),imshow(wa1),title('Watershed of Image 1');
subplot(224),imshow(wa2),title('Watershed of Image 2');
OUTPUT

EX 14
COLOR IMAGE PROCESSING
img1=imread('peppers.png');

subplot(551);
imshow(img1);
title('Original image');
img2=rgb2hsv(img1);
subplot(552);
imshow(img2);
title('HSV');
img3=rgb2ycbcr(img1);
subplot(553);
imshow(img3);
title('YCBCR');
img4=rgb2ntsc(img1);
subplot(554);
imshow(img4);
title('NTSC');
img5=img1(: , : , 1);
subplot(555);
imshow(img5);
img6=img1(: , : , 2);
subplot(556);
imshow(img6);
img7=img1(: , : , 3);
subplot(557);
imshow(img7);
img8=img2(: , : ,1);
subplot(558);
imshow(img8);
title('HUE');
img9=img2(: , :, 2);
subplot(559);
imshow(img9);
title('SATURATION');
img10=img2(: , : , 3);
subplot(5,5,10);
imshow(img10);
title('VALUE');
Red=img1;Blue=img1;Green=img1;
Red(:,:,2:3)=0;
subplot(5,5,11);
imshow(Red);
title('RED COMPONENT');
Green(:,:,1)=0;
subplot(5,5,12);
imshow(Green);

title('GREEN COMPONENT');
Blue(:,:,1:2)=0;
subplot(5,5,13);
imshow(Blue);
title('BLUE COMPONENT');
j=img3(: ,: ,1);
subplot(5,5,14);
imshow(j);
title('Y COMPONENT');
k=img3(: ,: ,2);
subplot(5,5,15);
imshow(k);
title('CB COMPONENT');
l=img3(: ,: ,3);
subplot(5,5,16);
imshow(l);
title('CR COMPONENT');
OUTPUT
CONVERSION BETWEEN COLOR SPACE

EX 15
IMAGE TYPE CONVERSION
img1=imread('onion.png');
img2=double(img1);
img3=makecform('srgb2lab');
img4=applycform(img2,img3);
subplot(331);

imshow(img4);
title('SRGB2LAB');
img5temp=makecform('lab2srgb');
img5=applycform(img2,img5temp);
subplot(332);
imshow(img5);
title('LAB2SRGB');
img6temp=makecform('srgb2xyz');
img6=applycform(img2,img6temp);
subplot(333);
imshow(img6);
title('SRGB2XYZ');
img7temp=makecform('uvl2xyz');
img7=applycform(img2,img7temp);
subplot(334);
imshow(img7);
title('UVL2XYZ');
img8temp=makecform('lch2lab');
img8=applycform(img2,img8temp);
subplot(335);
imshow(img8);
title('LCH2LAB');
img9temp=makecform('lab2lch');
img9=applycform(img2,img9temp);
subplot(336);
imshow(img9);
title('LAB2LCH');
img10temp=makecform('xyz2uvl');
img10=applycform(img2,img10temp);
subplot(337);
imshow(img10);
title('XYZ2UVL');
img11temp=makecform('xyl2xyz');
img11=applycform(img2,img11temp);
subplot(338);
imshow(img11);
title('XYL2XYZ');
img12temp=makecform('xyz2lab');
img12=applycform(img2,img12temp);
subplot(339);
imshow(img12);
title('XYZ2LAB');
CMPERMUTE

load trees
hsvmap=rgb2hsv(map);
[dum,index]=sort(hsvmap(:,3));
[Y,newmap]=cmpermute(X,map,index);
figure;
subplot(221);
image(X);
colormap(map);
title('Original image');
subplot(222);
rgbplot(map);
title('RGB plot of map');
subplot(223);
image(Y);
colormap(newmap);
title('Image after cmpermute');
subplot(224);
rgbplot(newmap);
title('Image after cmpermute');
subplot(224);
rgbplot(newmap);
title('RGB plot of image after cmpermute');
CMUNIQUE
load trees
subplot(121);
image(X);
colormap(map);
title('Original image');
axis off;
axis image;
[Y,newmap]=cmunique(X,map);
subplot(122);
image(Y);
colormap(newmap);
title('Image after cmunique');
axis off;
axis image;
CMAPPROX
load trees
subplot(121);
image(X);
colormap(map);

title('Original image');
axis off;
axis image;
[Y,newmap]=imapprox(X,map,0.5)
subplot(122);
image(Y);
colormap(newmap);
title('Image after cmapprox');
axis off;
axis image;
OUTPUT
IMAGE TYPE CONVERSION

CMPERMUTE

CMUNIQUE

CMAPPROX

You might also like