- There is a red line plot which corresponds to the original mapping (which is just an identity mapping).
- There is a blue line plot which shows the histogram-equivalence function obtained from the input image.
Plot of the histogram-equalization transformation function
22 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 (1)
larush
el 23 de En. de 2025 a las 9:58
Hey there Hamza
I’ve tried out your code on grayscale images, and it indeed does increase the contrast of the image using histogram equalization. To see the mapping from the old intensity values to the new intensity values, you can use the following code snippet;
figure;
plot(n,output,'b',LineWidth=2.5);
hold on;
plot(n,n,'r',LineWidth=1);
grid on;
xlabel('Original Intensity Levels');
ylabel('Mapped Intensity Levels');
title('Histogram-Equalization Transformation Function');
xlim([0 255]);
ylim([0 255]);
Here are a few pointers that explain the histogram-equivalence function plot;
Hope it helps you!
larush
0 comentarios
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!