【问题标题】:Histogram function imhist() produces a white line with black dots直方图函数 imhist() 产生一条带黑点的白线
【发布时间】:2013-12-27 23:33:47
【问题描述】:

我想使用内置函数 imhist() 查看图像的直方图,但我没有给我预期的直方图,而是用一条白线呈现。

这是我用来创建直方图的测试图像:http://tenettech.com/content/images/thumbs/0002817_basys2_spartan_3e_250k_gates_fpga_board_600.jpeg

这是我用来获取直方图的代码:

img = imread('test.jpg');
gray = rgb2gray(img);
hist = imhist(gray);
imshow(hist);

这是我从imshow(hist);得到的

http://i.imgur.com/0vCG7dx.jpg

很难看清楚,但在灰色背景下,它只是一条白线,顶部有黑点。

我期待这样的结果:http://nf.nci.org.au/facilities/software/Matlab/techdoc/ref/graphiac.gif

【问题讨论】:

    标签: matlab image-processing histogram


    【解决方案1】:

    imhist 的输出是计数向量,而不是图像(即,通过imshow 将这个数字的一​​维向量显示为图像将产生“黑点线”)。

    要么使用plot(或bar)显示直方图,要么使用不带任何输出参数的imhist 来获得(默认)直方图。

    nBins = 100; % 
    [counts, x] = imhist(gray, nBins);
    figure; bar(x, counts);
    
    figure; imhist(gray, nBins)
    

    【讨论】:

      【解决方案2】:

      直接使用即可:

      img = imread('test.jpg');
      gray = rgb2gray(img);
      figure,imhist(gray)
      figure, bar(imhist(img))
      figure,bar(imhist(img,50))
      

      【讨论】:

      • 谢谢,但在figure, bar(imhist(I))I 代表什么?
      猜你喜欢
      • 1970-01-01
      • 2011-01-28
      • 1970-01-01
      • 2013-08-05
      • 2018-09-12
      • 2012-08-14
      • 2021-08-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多