Professional Documents
Culture Documents
BM2406 Digital Image Processing Lab Manual
BM2406 Digital Image Processing Lab Manual
BM2406 Digital Image Processing Lab Manual
OUTPUT
HISTOGRAM EQUALIZATION WITHOUT 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);
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
EX 12
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