# Plot of the histogram-equalization transformation function

조회 수: 2 (최근 30일)
Hamza Ashraf 2022년 10월 1일
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
[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');

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

R2019a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by