How can I change the line color in the output of imhist?

10 ビュー (過去 30 日間)
Suresh Kumar
Suresh Kumar 2017 年 8 月 15 日
コメント済み: Image Analyst 2017 年 8 月 17 日
imhist provides the output in blue lines;i want to change it into say either red or green

採用された回答

Image Analyst
Image Analyst 2017 年 8 月 15 日
編集済み: Image Analyst 2017 年 8 月 15 日
For precise control, plot it yourself with bar() and then set the 'EdgeColor' and 'FaceColor' properties in the bar() function:
img = imread('moon.tif');
[counts, grayLevels] = imhist(img, 64);
bar(grayLevels, counts, 'EdgeColor', 'r', 'FaceColor', 'c', 'BarWidth', 0.95);
Makes cyan bars with red outlines.
  6 件のコメント
Suresh Kumar
Suresh Kumar 2017 年 8 月 17 日
But the output I am getting for findobj() is a zero matrix.. >> myhist=findobj(gca,'Type','Stem')
myhist =
Empty matrix: 0-by-1
Image Analyst
Image Analyst 2017 年 8 月 17 日
This worked for me:
img = imread('moon.tif');
imhist(img, 64);
myHist = findobj(gca, 'Type', 'Stem');
% Change the color to red
myHist.Color = [1 0 0]
but Suresh was wondering if it could all be done inside imhist() without a separate call to bar(), or to findobj() and myHist.Color.
Personally, I like the wider bars created by bar() rather than the single pixel wide lines by imhist's build in stem display.

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

その他の回答 (1 件)

Baptiste Ottino
Baptiste Ottino 2017 年 8 月 15 日
The histogram is a 'Stem' element. Use findobj to access its properties:
imhist(myImage);
myHist = findobj(gca, 'Type', 'Stem');
% Change the color to red
myHist.Color = [1 0 0]
If you use an older version of Matlab, you can replace the last line by:
% Change the color to red
set(myHist, 'Color', [1 0 0]);
Good luck!

カテゴリ

Help Center および File ExchangeExplore and Edit Images with Image Viewer App についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by