clc;
clear all;
close all;
A1=imread('E:\M.Tech\1st Semester\Image Processing\Lab\histogram.tif');
B1=A1;
[row column]=size(B1);
L=256;
MN=row*column;
nk=zeros(1,L); %nk is the number of pixels that have intensity rk.
for i=1:row
for j=1:column
nk(B1(i,j)+1)=nk(B1(i,j)+1)+1;
end
end
% The probability of occurence of intensity level rk in a image pr(rk).
nk=nk/MN;
% Transformation T(rk):a output image is obtained by transforming each
% pixel in the input image with intensity rk into a corresponding pixel
% with level sk in the output image.
s=zeros(1,L);
sum=0;
for k=1:L
sum=sum+nk(k);
s(k)=round((L-1)*sum);
end
% Equalization
equalized=zeros(1,L);
for i=1:L
equalized(s(i)+1)=equalized(s(i)+1)+nk(i);
end
% Convert the image using transformation s(k)
for i=1:row
for j=1:column
B1(i,j)=s(B1(i,j)+1);
end
end
figure;
subplot(2,2,1),imshow(A1),title('Original image');
subplot(2,2,2),imshow(B1),title('Equalized image');
subplot(2,2,3),bar(nk,'g'),title('Histogram of Original');
subplot(2,2,4),bar(equalized,'g'),title('Equalized Histogram');
No comments:
Post a Comment