フィルターのクリア

How to use bar() function in MATLAB to display histogram count as a bar graph?

38 ビュー (過去 30 日間)
Julie
Julie 2023 年 2 月 25 日
編集済み: Walter Roberson 2023 年 2 月 26 日
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.

回答 (2 件)

Image Analyst
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.

DGM
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);

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by