plot histogram without using matlab hist() function
Mostrar comentarios más antiguos
Hi all
There is a function called hist(), but if I want to plot a graph without using hist() command, how to plot a graph? I means using command to do the job same as hist().
Thank you.
2 comentarios
Aditi Shetty
el 19 de Ag. de 2018
A=imread('<your image path>');
a=rgb2gray(A);
subplot(3,1,1);
imshow(a);
title('original image');
[r,c]=size(a);
z=zeros(1,256);
for i=1:r
for j=1:c
b=a(i,j);
z(b+1)=z(b+1)+1;
end
end
N=sum(z);
p=zeros(1,256);
s=zeros(1,256);
c=zeros(1,256);
r=zeros(1,256);
for k=1:256
p(k)=z(k)/N;
if k==1
c(k)=p(k);
s(k)=c(k)*255;
r(k)=floor(s(k));
else
c(k)=c(k-1)+p(k);
s(k)=c(k)*255;
r(k)=floor(s(k));
end
end
subplot(3,1,3)
stem(r,z)
title('histogram')
Ritvik Ramesh Palvankar
el 10 de Sept. de 2019
Hey Adil,
Can you explain me the code after "for k=1:256". I did not understand the part where you took s(k)=c(k)*255
Also, why is zero matrix used and why is c(k-1) added to p(k)
Respuesta aceptada
Más respuestas (2)
Adrian Lukasik
el 13 de Mayo de 2015
Editada: Adrian Lukasik
el 13 de Mayo de 2015
0 votos
hello I have another problem. The same thing, but in 3D: There is a function called hist3(), but if I want to plot a graph without using hist3() command, how to plot a graph? I means using command to do the job same as hist3(). I have matrix b, 2x1000, and the task about making histogram plot without hist3() function.
Thank you.
1 comentario
Walter Roberson
el 13 de Mayo de 2015
You should open a new Question for that.
Once you have the counts for each grid-point, use bar3()
Saad Alzubaidi
el 24 de Sept. de 2022
clear all,clc;
x=imread(imgetfile);
imtool(x)
for r=1:3
v=x(:,:,r);
h(1:255,3)=0;
for i=1:size(x,1)
for j=1:size(x,2)
h(v(i,j)+1,r)=h(v(i,j)+1,r)+1;
end
end
end
figure,plot(h);
1 comentario
Saad Alzubaidi
el 24 de Sept. de 2022
This is the code you requested, for the color image.
Categorías
Más información sobre Histograms en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!