Contrast Streching: 'Img - JPG' 2

You might also like

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

Contrast Streching

itemp = imread('img.jpg');
i = itemp(:,:,2);
rtemp=min(i);
rmin=min(rtemp);
rtemp=max(i);
rmax=max(rtemp);
m=255/(rmax-rmin);
c=255-m*rmax;
i_new=m*i+c;
figure,imshow(i);
figure,imshow(i_new);
Thresholding

m=imread('img.jpg');
x=rgb2gray(m);
x=double(x);
tot=0;
[a,b]=size(x);
y=zeros(a,b);
for i=1:a
for j=1:b
y(i,j)=0;
end
end
for i=1:a
for j=1:b
tot=tot+x(i,j);
end
end
thr=tot/(a*b);
for i=1:a
for j=1:b
if x(i,j) >= thr
y(i,j)=1;
else
y(i,j)=0;
end
end
end
figure(1);
subplot(1,2,1);
imshow(m);
subplot(1,2,2);
imshow(y);
Bit plane Slicing

A=imread('img.jpg');
B=rgb2gray(A);
for i=1:400
for j=1:400
MSB(i,j)=bitand(B(i,j),bin2dec('10000000'));
LSB(i,j)=bitand(B(i,j),bin2dec('00000001'));
a(i,j)=bitand(B(i,j),bin2dec('01000000'));
b(i,j)=bitand(B(i,j),bin2dec('00100000'));
c(i,j)=bitand(B(i,j),bin2dec('00010000'));
d(i,j)=bitand(B(i,j),bin2dec('00001000'));
e(i,j)=bitand(B(i,j),bin2dec('00000100'));
f(i,j)=bitand(B(i,j),bin2dec('00000010'));
end
end
figure,imshow(MSB);
figure,imshow(LSB);
figure,imshow(a);
figure,imshow(b);
figure,imshow(c);
figure,imshow(d);
figure,imshow(e);
figure,imshow(f);
Histogram

A=imread('img.jpg');
g=rgb2gray(A);
figure(1);
subplot(1,2,1)
imshow(g);
title('gray image')
h=imhist(g);
h=h/sum(h);
ch=cumsum(h)+1;
hc=ch*255;
subplot(1,2,2);
bar(h);
title('histogram of image')
figure(2)
subplot(1,2,1);
bar(hc);
title('histogram equalization of image')

You might also like