Experiment-2: Goswami Pratikgiri R. (120420704006)

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

Experiment-2

Date: / /2013

AIM:
Read an 8 bit image and then apply different image enhancement
techniques:

(a) Brightness improvement

(b) Brightness reduction

(c) Thresholding

(d) Negative of an image

(e) Log transformation

(f) Power Law transformation.

Goswami Pratikgiri R.(120420704006) Page 1


(a) & (b) Brightness Improvement and Reduction

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

Goswami Pratikgiri R.(120420704006) Page 2


Goswami Pratikgiri R.(120420704006) Page 3
(c)Thresholding

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')

Goswami Pratikgiri R.(120420704006) Page 4


(d)Image Negative.

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:

Goswami Pratikgiri R.(120420704006) Page 5


(e)Log Transformation.

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')

Goswami Pratikgiri R.(120420704006) Page 6


(f)Power Law 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')

Goswami Pratikgiri R.(120420704006) Page 7


CONTRAST STRETCHING
clc;
close all;
clear all;

img = imread('cameraman.tif');

a=double(img);
[row col]=size(a);

LT=input('lower threshold:'); %10


UT=input('upper threshold:'); %150

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))

Goswami Pratikgiri R.(120420704006) Page 8


Goswami Pratikgiri R.(120420704006) Page 9

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy