添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

本页翻译不是最新的。点击此处可查看最新英文版本。

imhist

图像数据的直方图

说明

[ counts , binLocations ] = imhist( I ) 计算灰度图像 I 的直方图。 imhist 函数在 counts 中返回直方图计数,在 binLocations 中返回 bin 位置。直方图中 bin 的数量由图像类型确定。

[ counts , binLocations ] = imhist( I , n ) 指定用于计算直方图的 bin 的数量 n

[ counts , binLocations ] = imhist( X , cmap ) 计算具有颜色图 cmap 的索引图像 X 的直方图。对于颜色图中的每个条目,直方图中都有一个对应的 bin。

示例

imhist( ___ ) 显示绘制的直方图。如果输入图像是索引图像,则直方图在颜色图 cmap 的颜色条上方显示像素值分布。

示例

全部折叠

将灰度图像读入工作区。

I = imread('pout.tif');

显示图像的直方图。由于 I 是灰度图像,默认情况下直方图将有 256 个 bin。

imhist(I)

Figure contains 2 axes objects. Axes object 1 contains an object of type stem. Axes object 2 contains 2 objects of type image, line.

加载三维数据集。

load mristack

显示数据的直方图。由于图像是灰度图像, imhist 默认使用 256 个 bin。

imhist(mristack)

Figure contains 2 axes objects. Axes object 1 contains an object of type stem. Axes object 2 contains 2 objects of type image, line.

输入参数

全部折叠

灰度图像,指定为任意维度的数值数组。如果图像具有数据类型 single double ,则值必须在 [0, 1] 范围内。如果 I 的值超出范围 [0, 1],则可以使用 rescale 函数将值重新缩放到预期范围。

数据类型: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | logical

bin 的个数,指定为正整数。如果 I 是灰度图像,则 imhist 使用默认值,即 256 个 bin。如果 I 是二值图像,则 imhist 使用两个 bin。

示例: 50

数据类型: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

索引图像,指定为任意维度的数值数组。

数据类型: single | double | uint8 | uint16 | logical

与索引图像 X 相关联的颜色图,指定为由范围 [0, 1] 内的值组成的 c×3 数值矩阵。每行是一个三元素 RGB 三元组,它指定颜色图中单个颜色的红、绿和蓝分量。 颜色图的长度必须至少等于 X 中最大索引的长度。

数据类型: double

输出参数

全部折叠

直方图计数,以数值数组形式返回。如果为索引图像 X 计算直方图,则 counts 的长度与颜色图 cmap 的长度相同。

bin 位置,以数值数组形式返回。

提示

  • 对于灰度图像,直方图的 n 个 bin 中的每个都是宽度为 A/(n−1) 的半开区间。具体来说, pth (第 p 个)bin 是半开区间

    A ( p 1.5 ) ( n 1 ) B x < A ( p 0.5 ) ( n 1 ) B ,

    其中 x 是强度值。缩放因子 A 和偏移量 B 取决于图像类的类型,如下所示:

    数据类型 A B
    double 1 0
    single 1 0
    int8 255 128
    int16 65,535 32,768
    int32 4,294,967,295 2,147,483,648
    uint8 255 0
    uint16 65,535 0
    uint32 4,294,967,295 0
    logical 1 0

  • 要显示基于 counts binLocations 的直方图,请使用命令 stem (binLocations,counts)

扩展功能

版本历史记录

在 R2006a 之前推出

全部展开

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

MathWorks

Accelerating the pace of engineering and science