Experiment-2: Goswami Pratikgiri R. (120420704006)
Experiment-2: Goswami Pratikgiri R. (120420704006)
Experiment-2: Goswami Pratikgiri R. (120420704006)
Date: / /2013
AIM:
Read an 8 bit image and then apply different image enhancement
techniques:
(c) Thresholding
clc;
clear all;
close all;
img=imread('cameraman.tif');
i=input('enter 1 to improve brightness, 2 for brightness reduction : ');
if (i==1)
b=reshape(img,1,[]);
c=double(b);
d=c+100;
e=max(d);
f=length(d);
for i=1:1:f
g(i)=(255*d(i))/e;
end
subplot(2,1,1)
imshow(img)
title('original image')
j=uint8(g);
h=reshape(j,256,256);
subplot(2,1,2)
imshow(h)
title('improved brightness')
elseif (i==2)
b=reshape(img,1,[]);
c=double(b);
d=c-100;
e=max(d);
f=length(d);
for i=1:1:f
g(i)=(255*d(i))/e;
end
subplot(2,1,1)
imshow(img)
title('original image')
j=uint8(g);
h=reshape(j,256,256);
subplot(2,1,2)
imshow(h)
title('reduced brightness')
end
clc;
close all;
clear all;
img = imread('cameraman.tif');
a=img;
[row col]=size(a);
T=input('Enter value for Threshold ='); %100
for x=1:1:row
for y=1:1:col
if (img(x,y)<T)
a(x,y)=0; % s=0
else
a(x,y)=255; %s=L-1
end
end
end
subplot(2,1,1)
imshow(img);
title('original image')
subplot(2,1,2)
imshow(a)
title('after thresholding')
clc;
close all;
clear all;
img=imread('cameraman.tif');
negimg=256-1-img; % s= (L-1)-r
subplot(2,1,1)
imshow(img)
title('original image')
subplot(2,1,2)
imshow(negimg)
title('negative image')
Output:
clc;
clear all;
close all;
k=50;
a=imread('cameraman.tif');
b=reshape(a,1,[]);
c=double(b);
d=k*log10(1+c);
e=max(d);
f=length(d);
for i=1:1:f
g(i)=(255*d(i))/e;
end
subplot(2,1,1)
imshow(a)
title('original image')
j=uint8(g);
h=reshape(j,256,256);
subplot(2,1,2)
imshow(h)
title('image after log transformation')
clc;
clear all;
close all;
k=20;
q=input('enter power or gamma (more than 0) : '); %q=3
a=imread('cameraman.tif');
b=reshape(a,1,[]);
c=double(b);
d=k*power(c,q);
e=max(d);
f=length(d);
for i=1:1:f
g(i)=(255*d(i))/e;
end
subplot(2,1,1)
imshow(a)
title('original image')
j=uint8(g);
h=reshape(j,256,256);
subplot(2,1,2)
imshow(h)
title('image after power law transformation')
img = imread('cameraman.tif');
a=double(img);
[row col]=size(a);
for x=1:1:row
for y=1:1:col % slopes are l=0.5 , m=2 , n=0.5
if a(x,y)<=LT
b(x,y)=0.5*a(x,y); % s=l*r
else if a(x,y)<=UT
b(x,y)=2*(a(x,y)-LT)+0.5*LT; % s=m*(r-LT)+v
else b(x,y)=0.5*(a(x,y)-UT)+0.5*LT+2*(UT-LT); % s=n*(r-UT)+w
end
end
end
end
subplot(2,2,1)
imshow(img)
subplot(2,2,2)
imhist(img)
subplot(2,2,3)
imshow(uint8(b))
subplot(2,2,4)
imhist(uint8(b))