You are on page 1of 9

Experiment no-5

Aim: Introduction to Digital Image Processing in MATLAB.


Apparatus required: MATLAB R2009b
Post lab Exercise:

%reading image file


cd('C:\Users\Ankita\Desktop\pics')
I=imread('black.bmp')
imshow(I)

%reading image file


cd('C:\Users\Ankita\Desktop\pics')
imgData=imread('black.bmp');
[Rows,Cols]=size(imgData)
figure(1)
imshow(imgData);

for i=1:Rows
for j=1:Cols
if(i >Rows/4 && i<3*Rows/4)
if(j>Cols/4 && j<3*Cols/4)
imgData(i,j)=0;
end
end
end
end
figure(2);
imshow(imgData);

i=imread('pout.bmp');
figure(3);
imshow(i);
z=rgb2gray(image);

figure(4);
imshow(z);
[Rows,cols]=size(i)
y=imresize(z,[256,256],'nearest');
figure(5);
imshow(y);

%reading image file


cd('C:\Users\Ankita\Desktop\pics')
%reading colour image and appling various function on it
z=imread('pout.bmp');
[Rows,Cols]=size(z);
r1=[0,50];
r2=[50,100];
r3=[100,200];
r4=[255,255];
m1=3;
m2=2;
m3=1;
c1=r1(1,2)-m1*r1(1,1);
c2=r2(1,2)-m2*r2(1,1);
c3=r3(1,1)-m3*r3(1,1);
%% Transformation function
t=[];
for x=0:255
if(x<=r2(1,1))
t=[t (m1*x+c1)];
end

if(x>r2(1,1) && x<=r3(1,1))


t=[t (m2*x+c2)];
end
if(x>r3(1,1) && x<=r4(1,1))
t=[t (m3*x+c3)];
end
end
%% Getting output image
for n=1:Rows
for m=1:Cols
ot(n,m)=t(imagedata(n,m)+1);
end
end
plot(t)
grid on;
xlabel('Intensity in input image');
ylabel('Intensity in output image')
title('Piece-wise linear transformation : Contrast stretching function')

figure()
subplot(1,2,1)
imshow(z)
title('Original image')
subplot(1,2,2)
imshow(ot./255)
title('Contrast stretching')
Piece-wise linear transformation : Contrast stretching function
400

Intensity in output image

350
300
250
200
150
100
50

50

100
150
200
Intensity in input image

250

300

Original image
Contrast stretching

Learning outcome
In this experiment I learnt about Digital image processing basics. In this I learnt how to read a
image show it on screen then I learnt how to change dimension of a image and change it into

gray scale from RGB scale then check threshold of a image and then converting color image into
binary image and perform contrast sketching and adding brightness to it.

You might also like