Matching
Matching
%chini_ManDark
%0711016091
%Perform Histogram Equalization and matching on a given image. It is
%desired to have a Gaussian Distribution of image. Show the histogram for
%both the cases.
yt=zeros(1,256);
x=1:256;
sigma=30; mu=250; A=3;
y=A*exp(-(x-mu).^2/(2*sigma^2))+rand(size(x))*0.1;
y=y/300;
gz=zeros(1,256);
for i=1:256
for j=i:-1:1
yt(i)=yt(i)+y(j);
end
end
p=zeros(1,256);
pt=zeros(1,256);
Im=imread('gs.jpg');
subplot(231)
imshow(Im)
title('Original Image')
for m=1:250
for n=1:250
for g=1:256
if Im(m,n)==g-1
p(g)=p(g)+1;
end
end
end
end
for g=1:256
p(g)=p(g)/62500;
end
for g=1:256
for q=g:-1:1
pt(g)=pt(g)+p(q);
end
end
for g=1:256
s(g)=255*pt(g);
end
for m=1:250
for n=1:250
count=0;
for r=1:256
if count==0
if Im(m,n)==r-1
Im(m,n)=s(r);
count=1;
end
end
end
end
end
subplot(232)
imshow(Im)
title('Equalized Image')
subplot(235)
imhist(Im)
xlabel('Gray levels')
ylabel('Probability of occurence')
title('Histogram of Equalised Image')
for i=1:256
gz(i)=255*yt(i);
end
subplot(234)
plot(y)
ylabel('Amplitude')
xlabel('Gray Levels')
title('Given Probability Distribution')
for m=1:250
for n=1:250
count=0;
for q=1:256
if count==0
if (Im(m,n)-gz(q)) <= 0.5
Im(m,n)=q-1;
count=1;
end
end
end
end
end
subplot(233)
imshow(Im)
title('Matched Image')
subplot(236)
imhist(Im)
xlabel('Gray levels')
ylabel('Probability of occurence')
title('Histogram of Matched Image')