Plot of the histogram-equalization transformation function
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello, I have a code that plots the histogram of an image and do histogram-equalization without using built in fucntions and runs accurately. Am attaching a code for the refrence. Now I need to plot the histogram-equalization transformation function and I can not understand how to do it. Need some help doing it.
% Plot histogram
x=imread('n3.jpg');% To read image
[M,N]=size(x);
t=1:256;
n=0:255;
count=0;
for z=1:256
for i=1:M
for j=1:N
if x(i,j)==z-1
count=count+1;
end
end
end
t(z)=count;
count=0;
end
% disp(t')
histgram=stem(n,t);
grid on;
ylabel('no. of pixels with intensity levels---->');
xlabel('intensity levels---->'); title('HISTOGRAM OF THE IMAGE')
% Histogram-Equilization
numofpixels=size(x,1)*size(x,2);
figure,imshow(x);
title('Original Image');
Hx=uint8(zeros(size(x,1),size(x,2)));
freq=zeros(256,1);
probf=zeros(256,1);
probc=zeros(256,1);
cum=zeros(256,1);
output=zeros(256,1);
%freq counts the occurrence of each pixel value.
%The probability of each occurrence is calculated by probf.
for i=1:size(x,1)
for j=1:size(x,2)
value=x(i,j);
freq(value+1)=freq(value+1)+1;
probf(value+1)=freq(value+1)/numofpixels;
end
end
sum=0;
no_bins=255;
%The cumulative distribution probability is calculated.
for i=1:size(probf)
sum=sum+freq(i);
cum(i)=sum;
probc(i)=cum(i)/numofpixels;
output(i)=round(probc(i)*no_bins);
end
for i=1:size(x,1)
for j=1:size(x,2)
Hx(i,j)=output(x(i,j)+1);
end
end
figure,imshow(Hx);
title('Histogram equalization');
0 comentarios
Respuestas (0)
Ver también
Categorías
Más información sobre Histograms en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!