필터 지우기
필터 지우기

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 CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by