How to use bar() function in MATLAB to display histogram count as a bar graph?
38 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
We have an original image which I took it from my mobile device, so I used the subplot function to change the color image to 5 images with different brightness(already converted the color image to a gray-level image), and I need to use to bar function to make each gray-level image has their own histogram, so I will get 5 histograms with different brightness level gray-level image, but I don't know how to create a different histogram with the bar function and imhist function, anyone would like to contribute your ideas? thank you.
0 commentaires
Réponses (2)
Image Analyst
le 25 Fév 2023
Try this
edge = 0:256;
% Image 1
[counts, grayLevels] = histcounts(image1, edges);
subplot(2, 3, 1);
bar(grayLevels(1:end-1), counts);
title('Histogram of Image1');
% Image 2
[counts, grayLevels] = histcounts(image2, edges);
subplot(2, 3, 2);
bar(grayLevels(1:end-1), counts);
title('Histogram of Image2');
Repeat for images 3-5, changing the last argument in subplot to 3, 4, and 5.
0 commentaires
DGM
le 25 Fév 2023
Is there a particular reason we're avoiding imhist()?
inpict = imread('cameraman.tif');
% you could use histcounts() and bar()
subplot(3, 1, 1);
edges = 0:256;
[counts, grayLevels] = histcounts(inpict, edges);
bar(grayLevels(1:end-1), counts);
% or you could use imhist() and bar()
subplot(3, 1, 2);
[counts edges] = imhist(inpict);
bar(edges, counts);
% or you could just use imhist()
subplot(3, 1, 3);
imhist(inpict);
0 commentaires
Voir également
Catégories
En savoir plus sur Data Distribution Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!