Obtaining Histogram of Image Stored in Cell Array

3 ビュー (過去 30 日間)
itend
itend 2017 年 8 月 30 日
コメント済み: itend 2017 年 9 月 6 日
Hello,
I have a cell array called output. Output contains matrices of size 1024 x 1024, type = double, grayscale. I would like to plot each matrix and its corresponding histogram on a single plot. Here is what I have so far:
for i = 1:size(output,2)
figure
subplot(2,1,1)
imagesc(output{1,i});
colormap('gray')
colorbar;
title(num2str(dinfo(i).name))
subplot(2,1,2)
[pixelCount, grayLevels] = imhist(output{1,i});
bar(pixelCount);
title('Histogram of original image');
xlim([0 grayLevels(end)]); % Scale x axis manually.
grid on;
end
The plot I get, however, seems to be faulty... I was expecting a distribution of bars.
I am somewhat lost at how to proceed, any help or suggestions would be appreciated!
Thanks :)

採用された回答

Image Analyst
Image Analyst 2017 年 9 月 5 日
Instead of this
[pixelCount, grayLevels] = imhist(output{1,i});
bar(pixelCount);
try this:
histogram(output{1,i}, 256);
grid on;
  1 件のコメント
itend
itend 2017 年 9 月 6 日
Thank you for your response.
This works!

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

その他の回答 (1 件)

Aylin
Aylin 2017 年 9 月 5 日
This issue might be caused due to the difference between the binLocations output of the imhist command and the x-axis scale for the bar graph. For example:
A = rand(1024); % generate some example data
[counts, binLocations] = imhist(A); % generate histogram bins
bar(counts); % plot histogram data into bar graph
After executing the above code, examine the value of the binLocations variable. It would have a range between 0 to 1, while the histogram would have an x-axis between 0 to 255. Therefore, the following line of code:
xlim([0 binLocations(end)]);
would limit the bar graph to a range of 0 to 1, while the actual data is plotted on a range from 0 to 255. If you would like to show the full range of the bar graph, the following may work better:
xlim([0 numel(binLocations)])
However, if you would like to scale the x-axis of the bar graph correctly between 0 and 1, the following might work better:
bar(binLocations, counts); % provide both x and y inputs to the 'bar' function
xlim([0 binLocations(end)]); % apply x-axis limits
For more information, please refer to the MATLAB documentation pages for bar , numel , and imhist .
  1 件のコメント
itend
itend 2017 年 9 月 6 日
Thank you for your response.

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

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by