【问题标题】:Using "imhist" function in Matlab to plot multiple histograms on the same figure在 Matlab 中使用“imhist”函数在同一图形上绘制多个直方图
【发布时间】:2013-08-05 09:07:33
【问题描述】:

我是 Matlab 新手,正在尝试做一些图像处理。我有两张彩色图像,可以转换为灰度图像。我的目标是能够将两个灰度图像的直方图放在同一个数字上,以便我可以比较它们。我的代码如下所示:

a=imread('image1.jpg')
agray=rgb2gray(a)
b=imread('image2.jpg')
bgray=rgb2gray(b)
figure,imhist(agray)
figure,imhist(bgray)

代码可以很好地独立查看两个直方图,但我可以找到如何将它们组合成一个图进行比较。请帮忙!!

【问题讨论】:

    标签: matlab image-processing histogram multiple-tables figure


    【解决方案1】:

    如果你想要两个在同一个 axes 并且你不介意失去下栏,试试这个(我现在没有图像工具箱,所以我没有测试它):

    a=imread('image1.jpg')
    agray=rgb2gray(a)
    b=imread('image2.jpg')
    bgray=rgb2gray(b)
    [counts,x] = imhist(agray)
    stem(counts,x,'b')
    hold on
    [counts,x] = imhist(bgray)
    stem(counts,x,'r')
    

    【讨论】:

    • 看起来像 stem(x,counts,'b','Marker','none'); 更好(也许只是在我的 matlab 版本上)。另外,; 是你的朋友 ;>)
    • 是的,没有标记会更好;也更类似于没有输出参数的imhist 所做的
    • 效果很好!!非常感谢您的帮助!
    • 不客气!如果答案对您有用,则 StackOverflow 中的标准做法是将其标记为“已接受”(答案左侧的勾号)。您只能将每个问题标记为已接受一个答案。我告诉你这个以防你不知道,因为我看到你是新来的。
    【解决方案2】:

    试试这个!

    figure (x),
    subplot(2,1,1); imhist(agray);
    subplot(2,1,2); imhist(bgray);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-21
      • 2020-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多