Extract data from a histogram

12 ビュー (過去 30 日間)
elTurco
elTurco 2023 年 4 月 7 日
編集済み: Image Analyst 2023 年 4 月 7 日
I have a 256 x 256 pixel gray image. I drew the histogram of this image in matlab. I need to find the total number of pixels in each of the 0-64,64-128,128-192 and 192-255 gray levels. I've plotted the histogram but I can't get the pixel values. Is anyone you help?

採用された回答

Image Analyst
Image Analyst 2023 年 4 月 7 日
Try this:
grayImage = imread('cameraman.tif');
subplot(2, 1, 1);
imshow(grayImage, []);
subplot(2, 1, 2);
imhist(grayImage); % Display histogram
grid on;
edges = [0 : 64 : 255, 255]
edges = 1×5
0 64 128 192 255
[counts, edges] = histcounts(grayImage, edges)
counts = 1×4
16032 10445 37886 1173
edges = 1×5
0 64 128 192 255
  2 件のコメント
elTurco
elTurco 2023 年 4 月 7 日
Thank you very much for the help...I need to find the mean and standard deviation of the pixels in each range (0-64,64-128,128-192,192-255). how can I find that?
Image Analyst
Image Analyst 2023 年 4 月 7 日
編集済み: Image Analyst 2023 年 4 月 7 日
For example, for one range:
mask = (grayImage >= 0) & (grayImage <= 64);
numPixelsInRange = nnz(mask)
stdDev = std(grayImage(mask))
theMean = mean(grayImage(mask))

サインインしてコメントする。

その他の回答 (1 件)

dpb
dpb 2023 年 4 月 7 日
移動済み: Image Analyst 2023 年 4 月 7 日
Use histcounts as direct solution instead. The data are inside the histogram but you've got to go "handle diving" to retrieve them if you didn't save the object handle when called it; if you did then see the 'Properties' section of the doc for it (link to in the 'See Also') section. All in all, it's easier to just use histcounts

カテゴリ

Help Center および File ExchangeHistograms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by