码迷,mamicode.com
首页 > 其他好文 > 详细

MATLAB中 histogram 和 imhist 的区别

时间:2017-10-22 22:04:36      阅读:526      评论:0      收藏:0      [点我收藏+]

标签:cat   none   name   mod   结果   图像   reference   form   enc   

matlab有两个生成直方图的库函数,分别是imhist和histogram,二者有何区别呢?

区别就是:

  • imhist
    • 官方help:imhist(I) calculates the histogram for the intensity image I and displays a plot of the histogram. The number of bins in the histogram is determined by the image type.
    • 可见,imhist的NumBins值是由图像类型决定的。若图像为uint8类型,则bin的数量为256,即[0:1:255]。
  • histogram(早期版本为hist,现在matlab已不建议使用hist了)

    • 官方help:
      histogram(X) creates a histogram plot of X. The histogram function uses an automatic binning algorithm that returns bins with a uniform width, chosen to cover the range of elements in X and reveal the underlying shape of the distribution. histogram displays the bins as rectangles such that the height of each rectangle indicates the number of elements in the bin.

              nbins — Number of bins
         Number of bins, specified as a positive integer. If you do not specify nbins, then histogram automatically calculates how many bins to use based on the values in X.

    • 可见,histogram的NumBins值可以人为设定,在未指定该参数时,系统将基于图像的灰度分布自动计算NumBins的值。

例程:

 1 imgColor = imread(lena.jpg);
 2 imgGray = rgb2gray(imgColor);
 3 
 4 %% imhist
 5 figure(name, imhist),
 6 imhist(imgGray);
 7 
 8 %% histogram
 9 figure(name, histogram auto),
10 % histogram函数自动计算NumBins值
11 hist2 = histogram(imgGray);
12 % Find the bin counts
13 binCounts = hist2.Values;
14 % Get bin number
15 binNum = hist2.NumBins;
16 
17 %% histogram 指定NumBins值
18 % Specify number of histogram bins
19 figure(name, histogram256),
20 hist256 = histogram(imgGray, 256); % 等同于 imhist(imgGray)

 


由运行结果也可看出,histogram(imgGray, 256)与imhist(imgGray),二者在最大bin的灰度累计值是一样的。

 

技术分享

 

reference

MATLAB中 histogram 和 imhist 的区别

标签:cat   none   name   mod   结果   图像   reference   form   enc   

原文地址:http://www.cnblogs.com/gxcdream/p/7710729.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!