How to use bar() function in MATLAB to display histogram count as a bar graph?
38 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Image Analyst
2023-2-25
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 个评论
DGM
2023-2-25
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!