Download as pdf or txt
Download as pdf or txt
You are on page 1of 39

DIGITAL IMAGE PROCESSING

LAB FILE
ECS-752

SUBMITTED TO SUBMITTED BY
Digital Image Processing Lab

Digital Image Processing Lab Index

S. NAME OF THE PROGRAM DATE SIGN REMARK


No.
1 Implement image enhancement in spatial
domain
1.a Contrast manipulation
1.b Histogram equalization
1.c Threshold operation
1.d Spatial domain filtering
1.e Histogram of original & flipped image
2 Implement image enhancement in frequency
domain
2.a Image addition

2.b Image subtraction


2.c Blending of two images
3 Implement image segmentation in MATLAB
3.a Compute the edges in the image
4 Implement morphological image processing in
MATLAB
4.a Dilation & erosion
4.b Boundary detector
5 Implement colour image processing in MATLAB
5.a To extract red, green & blue component
5.b To remove the RGB plane
5.c Histogram Equalization of coloured image
5.d Perform the median filtering of colour image
5.f To separate an object from its background

Page 2
Digital Image Processing Lab

PROGRAM NO. 1

Implement Image Enhancement in Spatial Domain

1a) CONTRAST MANIPULATION

clc clear

all close

all

a=imread('onion.png')

b=a*0.4

c=a*2

subplot(1,3,1),imshow(a),title('Original Image')

subplot(1,3,2),imshow(b),title('Decrease in Contrast')

subplot(1,3,3),imshow(c),title('Increase in Contrast')

Page 3
Digital Image Processing Lab

OUTPUT :

Page 4
Digital Image Processing Lab

1b) HISTOGRAM EQUALIZATION

clc clear

all close

all

a=imread('coins.png')

b=histeq(a)

subplot(2,2,1),imshow(a),title('Original Image')

subplot(2,2,2),imshow(b),title('after histogram equalization')

subplot(2,2,3),imhist(a),title('Original Image')

subplot(2,2,4),imhist(b),title('after histogram equalization')

Page 5
Digital Image Processing Lab

OUTPUT :

Page 6
Digital Image Processing Lab

1c) THRESHOLD OPERATION

clc clear

all close

all

a=imread('coins.png')

[m,n]=size(a)

t=input('enter the value of threshold parameter')

for i=1:m

for j=1:n

if a(i,j)<t

b(i,j)=0;

else

b(i,j)=255;

end

end

end

figure,imshow(a),title('Original image'),pixval on

figure,imshow(b),title('threshold image'),pixval on

Page 7
Digital Image Processing Lab

OUTPUT :

Page 8
Digital Image Processing Lab

Page 9
Digital Image Processing Lab

1d) SPATIAL DOMAIN FILTERING

clc clear

all close

all

a=imread('coins.png')

h1=1/9*ones(3,3)

h2=1/25*ones(5,5)

b1=conv2(a,h1);

b2=conv2(a,h2);

imshow(a),title('original image')

imshow(uint8(b1)),title('output using 3*3 mask')

imshow(uint8(b2)),title('output using 5*5 mask')

Page 10
Digital Image Processing Lab

OUTPUT :

Page 11
Digital Image Processing Lab

Page 12
Digital Image Processing Lab

1e) HISTOGRAM OF ORIGINAL AND FLIPPED IMAGE

clc clear

all close

all

a=imread('coins.png')

b=fliplr(a)

subplot(2,2,1),imshow(a),title('original image')

subplot(2,2,2),imshow(b),title('flipped image')

subplot(2,2,3),imhist(a),title('original image')

subplot(2,2,4),imhist(b),title('flipped image')

Page 13
Digital Image Processing Lab

OUTPUT :

Page 14
Digital Image Processing Lab

PROGRAM NO. 2

Implement Image Enhancement in Frequency Domain.

2a) IMAGE
ADDITION clc

clear all

close all

a=imread('circles.png')

b=imread('cameraman.tif')

c=double(a)+double(b)

subplot(2,2,1),imshow(a),title('Addition of two image')

subplot(2,2,2),imshow(b),title('Addition of two image')

subplot(2,2,3),imshow(uint8(c)),title('Addition of two image')

Page 15
Digital Image Processing Lab

OUTPUT :

Page 16
Digital Image Processing Lab

2b) Image Subtraction:

clc

clear all

close all

a=imread('circles.png')

b=imread('cameraman.tif')

c=double(a)-double(b)

subplot(2,2,1),imshow(a),title('substraction of two image')

subplot(2,2,2),imshow(b),title('substraction of two image')

subplot(2,2,3),imshow(uint8(c)),title('substraction of two image')

Page 17
Digital Image Processing Lab

OUTPUT :

Page 18
Digital Image Processing Lab

2c) BLENDING OF TWO IMAGES

clc

clear all

close all

a=imread('cameraman.tif');
b=imread('coins.png');
b=imresize(b,[256 256]);

[m n]=size(a);

alpha1=input('enter the value of alpha :');


alpha2=input('enter the value of alpha :');
alpha3=input('enter the value of alpha :');
alpha4=input('enter the value of alpha :');

for i=1:m
for j=1:n
c1(i,j)=(1-alpha1)*a(i,j)+alpha1*b(i,j);
c2(i,j)=(1-alpha2)*a(i,j)+alpha2*b(i,j);
c3(i,j)=(1-alpha3)*a(i,j)+alpha3*b(i,j);
c4(i,j)=(1-alpha4)*a(i,j)+alpha4*b(i,j);
end
end

subplot(2,2,1),imshow(c1),title('blended image')
xlabel(sprintf('alpha value is %g',alpha1))

subplot(2,2,2),imshow(c2),title('blended image')
xlabel(sprintf('alpha value is %g',alpha2))

subplot(2,2,3),imshow(c3),title('blended image')
xlabel(sprintf('alpha value is %g',alpha3))

subplot(2,2,4),imshow(c4),title('blended image')
xlabel(sprintf('alpha value is %g',alpha4))

Page 19
Digital Image Processing Lab

OUTPUT :

Page 20
Digital Image Processing Lab

PROGRAM NO. 3

Implement Image Segmentation in MAT Lab.

COMPUTE THE EDGES IN THE IMAGE.

clc

clear all

close all

a=imread('onion.png')

a=rgb2gray(a)

b=edge(a,'roberts');

c=edge(a,'sobel');

d=edge(a,'prewitt');

e=edge(a,'log');

f=edge(a,'canny');

figure,imshow(a),title('original image')

figure,imshow(b),title('robert')

figure,imshow(c),title('sobel')

figure,imshow(d),title('prewitt')

figure,imshow(e),title('log')

figure,imshow(f),title('canny')

Page 21
Digital Image Processing Lab

OUTPUT :

Page 22
Digital Image Processing Lab

Page 23
Digital Image Processing Lab

PROGRAM NO. 4

Implement morphological image processing in MAT Lab.

4a) DILATION AND EROSION

clc clear

all close

all

a=imread('text.png')

b=[1 1 1;1 1 1;1 1 1]

a1=imdilate(a,b)

a2=imerode(a,b)

figure,imshow(a),title('original image')

figure,imshow(a1),title('dilute image')

figure,imshow(a2),title('eroded image')

Page 24
Digital Image Processing Lab

OUTPUT :

Page 25
Digital Image Processing Lab

4b) BOUNDARY DETECTOR

clc

clear all

a=imread(‘text.png’)

b=[0 1 0;1 1 1;0 1 0]

a1=imdilate(a,b)

a2=imerode(a,b)

a3=a1-a2

a4=a1-a

a5=a1-a2

figure, imshow(a), title(‘Original Image’)

figure, imshow(a1), title(‘Dilated Image’)

figure, imshow(a2), title(‘Eroded Image’)

figure, imshow(a3), title(‘First Property’)

figure, imshow(a4), title(‘Second Property’)

figure, imshow(a5), title(‘Third Property’)

OUTPUT :

Page 26
Digital Image Processing Lab

PROGRAM NO. 5
Page 27
Digital Image Processing Lab

Implement Colour Image Processing in MAT Lab.

5a) TO EXTRACT RED, GREEN, AND BLUE COMPONENT

clc clear

all close

all

rgb=imread('onion.png')

r=rgb

g=rgb

b=rgb

r( : , : , 2 )=0

r( : , : , 2 )=0

b( : , : , 1 )=0

b( : , : , 3 )=0

g( : , : , 1 )=0

g( : , : , 2 )=0

imshow(rgb),title)'original image')

figure,imshow(r),title('red component')

figure,imshow(g),title('green component')

figure,imshow(b),title('blue component')

Page 28
Digital Image Processing Lab

OUTPUT :

Page 29
Digital Image Processing Lab

5b) TO REMOVE THE RGB PLANE

clc clear

all close

all

a=imread('onion.png')

a1=a

b1=a

c1=a

a1(:,:,1)=0

b1(:,:,2)=0

c1(:,:,3)=0 imshow(a),title('original

image') figure,imshow(a1),title('gb

sector') figure,imshow(b1),title('br

sector') figure,imshow(c1),title('rg

sector')

Page 30
Digital Image Processing Lab

OUTPUT :

Page 31
Digital Image Processing Lab

5c) HISTOGRAM EQUALIZATION OF COLOURED IMAGE

clc

clear all

a=imread('onion.png')

b=rgb2ntsc(a);

b(: , : , 1)=histeq(b(: , : , 1))

c=ntsc2rgb(b);

imshow(a),title('original image')

figure,imshow(c),title('Histogram equalized image')

Page 32
Digital Image Processing Lab

OUTPUT :

Original Image

Histogr

am equalized image

Page 33
Digital Image Processing Lab

5d) PERFORM THE MEDIAN FILTERING OF COLOUR


IMAGE

clc clear

all close

all

a=imread('onion.png')

b=imnoise(a,'salt & pepper',0.2)

c( : , : , 1 )=medfilt2(b( : , : , 1 ))

c( : , : , 2 )=medfilt2(b( : , : , 2 ))

c( : , : , 3 )=medfilt2(b(: , : , 3 ))

imshow(a),title('original image')

figure,imshow(b),title('corrupted image')

figure,imshow(c),title('median filtered image')

Page 34
Digital Image Processing Lab

OUTPUT :

Page 35
Digital Image Processing Lab

5e) TO SEPARATE AN OBJECT FROM ITS BACKGROUND

clc

clear all

a=imread(‘onion.png’)

b=rgb2ycbr(a)

mask=b( : , : , 2)>120

imshow(a),title(‘Original image’)

figure,imshow(mask),title(‘Segmented Image’)

Page 36
Digital Image Processing Lab

OUTPUT :

Original Image

Segmented image

Page 37
Digital Image Processing Lab

Page 38

You might also like