主要内容

image

显示来自数组的图像

描述

example

图片(C)displays the data in arrayC作为图像。每个元素C指定的颜色1像素的图像。的resulting image is anm-经过-ngrid of pixels wheremis the number of rows andnis the number of columns inC。的row and column indices of the elements determine the centers of the corresponding pixels.

example

图片(x,y,C)specifies the image location. Usexandyto specify the locations of the corners corresponding toC(1,1)andC(m,n)。To specify both corners, setxandyas two-element vectors. To specify the first corner and letimagedetermine the other, setxandy作为标量值。图像被拉伸并定向为适用。

图像('cdata',C)将图像添加到当前轴上,而无需更换现有图。该语法是低级版本的图像(C)。有关更多信息,请参阅High-Level Versus Low-Level Version of Image

图片('XData',x,'YData',y,“ cdata',C)specifies the image location. This syntax is the low-level version of图像(x,y,c)

example

图片(___,姓名,Value)specifies image properties using one or more name-value pair arguments. You can specify image properties with any of the input argument combinations in the previous syntaxes.

图片(ax,___)creates the image in the axes specified byaxinstead of in the current axes (GCA). The optionaxcan precede any of the input argument combinations in the previous syntaxes.

example

im= image(___)returns theImageobject created. Useim创建图像后设置属性。You can specify this output with any of the input argument combinations in the previous syntaxes. For a list of image properties and descriptions, see图像属性

例子

collapse all

Create matrixC。Display an image of the data inC。Add a colorbar to the graph to show the current colormap.

C = [0 2 4 6;8 10 12 14;16 18 20 22];图像(c)配色栏

Figure contains an axes object. The axes object contains an object of type image.

默认情况下,CDataMappingproperty for the image is set to'direct'soimage解释值Cas indices into the colormap. For example, the bottom right pixel corresponding to the last element inC, 22, uses the 22nd color of the colormap.

Scale the values to the full range of the current colormap by setting theCDataMappingproperty to'scaled'when creating the image.

图像(c,'CDataMapping','scaled') colorbar

Figure contains an axes object. The axes object contains an object of type image.

或者,您可以使用imagescfunction to scale the values instead of using图像(c,'CDataMapping','scaled')。例如,useimagsc(c)

将图像放置在5到8之间x- 轴,在3至6之间y-轴。

x = [5 8];y = [3 6];C = [0 2 4 6;8 10 12 14;16 18 20 22];图像(x,y,c)

Figure contains an axes object. The axes object contains an object of type image.

请注意,与C(1,1)相对应的像素以(5,3)为中心。对应于C(3,4)的像素以(8,6)为中心。imagepositions and orients the rest of the image between those two points.

CreateC作为真实颜色的3-D阵列。通过将数组的最后两页设置为零来使用红色。

C = zeros(3,3,3); C(:,:,1) = [.1 .2 .3; .4 .5 .6; .7 .8 .9]
c = c(:,:,1)= 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000 0.8000 0.8000 0.9000 C(:, :, :, :,2)= 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 C(:, :, :,3)= 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0

Display an image of the data inC

图像(C)

Figure contains an axes object. The axes object contains an object of type image.

绘制一条线,然后在行顶部创建图像。返回图像对象。

情节(1:3)保持onC = [1 2 3;4 5 6;7 8 9];im =图像(c);

Figure contains an axes object. The axes object contains 2 objects of type line, image.

Make the image semitransparent so that the line shows through the image.

im.alphadata = 0.5;

Figure contains an axes object. The axes object contains 2 objects of type line, image.

Read a JPEG image file.

C = imread('ngc6543a.jpg');

imread返回650 x600 x-3阵列,C

显示图像。

图像(C)

Figure contains an axes object. The axes object contains an object of type image.

创建一个表面图。然后,在表面下添加图像。imagexy-plane.

z = 10 +峰;冲浪(z)握住on图片(Z,'CDataMapping','scaled')

Figure contains an axes object. The axes object contains 2 objects of type surface, image.

Input Arguments

collapse all

Image color data, specified in one of these forms:

  • Vector or matrix — This format defines indexed image data. Each element ofCdefines a color for 1 pixel of the image. For example,C = [1 2 3;4 5 6;7 8 9];。元素Cmap to colors in the colormap of the associated axes. TheCDataMappingproperty controls the mapping method.

  • RGB三重态的3-D数组 - 此格式使用RGB三重态值定义了真实的颜色图像数据。每个RGB三重态定义了图像的1像素的颜色。RGB三重态是一个三元素向量,它指定了颜色的红色,绿色和蓝色组件的强度。3-D数组的第一页包含红色组件,第二页包含绿色组件,第三页包含蓝色组件。由于图像使用真实颜色代替colormap颜色,因此CDataMappingproperty has no effect.

    • IfCis of type双倍的,然后是RGB三重态值[0 0 0]corresponds to black and[1 1 1]对应于白色。

    • IfCis an integer type, then the image uses the full range of data to determine the color. For example, ifCis of typeUINT8, then[0 0 0]corresponds to black and[255 255 255]对应于白色。IfCDatais of typeint8, then[-128 -128 -128]corresponds to black and[127 127 127]对应于白色。

    • IfCis of typelogical, then[0 0 0]corresponds to black and[1 1 1]对应于白色。

This illustration shows the relative dimensions ofC对于两种颜色模型。

颜色图像数据或CDATA的图表,用于索引颜色和真实颜色。索引颜色的CDATA是m-n-n数组。真实颜色的CDATA是m-n-by-3阵列。

行为NaN元素未定义。

使用低级版本的imagefunction instead, set theCData属性作为名称值对。例如,图像('cdata',c)

Converting Between双倍的and Integer Data Types

When you call theimagefunction with a vector or 2-D matrix and use the defaultCDataMapping价值,您必须在之间转换时将数据值偏移1双倍的值and integer types. This offset is not necessary whenCDataMapping被设定为'scaled'

例如,如果U8contains indexed image data of typeUINT8, you can convert it to type双倍的using:

d = double(u8) + 1;

从类型转换索引图像数据双倍的对于整数类型,减去1并使用圆形的确保所有值都是整数。例如,如果Dcontains indexed image data of type双倍的, convert it toUINT8using:

U8 = uint8(round(D - 1));

Converting Between Normalized双倍的and Truecolor Values

将真实的颜色图像数据从整数类型转换为类型双倍的, rescale the data. For example, ifRGB8is true color image data of typeUINT8, convert it to双倍的using:

rgb = double(rgb8)/255;

从类型转换真颜色图像数据双倍的to an integer type, rescale the data and use圆形的确保所有值都是整数。例如,如果RGB是类型的图像数据双倍的, convert it toUINT8using:

RGB8 = uint8(round(RGB*255));

数据类型:single|双倍的|int8|INT16|INT32|INT64|UINT8|UINT16|UINT32|uint64|logical

Placement along thex-axis, specified in one of these forms:

  • 两元素向量 - 使用第一个元素作为中心的位置C(1,1)第二个要素作为中心的位置C(m,n), 在哪里[m,n] =尺寸(c)。IfCis a 3-D array, thenmandnare the first two dimensions. Evenly distribute the centers of the remaining elements ofC在这两个点之间。

    每个像素的宽度由表达式确定:

    (x(2)-x(1))/(size(C,2)-1)

    Ifx(1)>x(2),然后将图像翻转为左右。

  • 标量 - 中心C(1,1)at this location and each following element one unit apart.

使用低级版本的imagefunction instead, set theXData属性作为名称值对。例如,图片('XData',x,'YData',y,'CData',C)

You cannot interactively pan or zoom outside the x-axis limits or y-axis limits of an image, unless the limits are already set outside the bounds of the image. If the limits are already outside the bounds, there is no such restriction. If other objects (such as a line) occupy the axes and extend beyond the bounds of the image, you can pan or zoom to the bounds of the other objects, but no further.

数据类型:single|双倍的|int8|INT16|INT32|INT64|UINT8|UINT16|UINT32|uint64|logical

Placement alongy-axis, specified in one of these forms:

  • 两元素向量 - 使用第一个元素作为中心的位置C(1,1)第二个要素作为中心的位置C(m,n), 在哪里[m,n] =尺寸(c)。IfCis a 3-D array, thenmandnare the first two dimensions. Evenly distribute the centers of the remaining elements ofC在这两个点之间。

    的height of each pixel is determined by the expression:

    (y(2)-y(1))/(size(c,1)-1)

    Ify(1)>y(2), then the image is flipped up-down.

  • 标量 - 中心C(1,1)at this location and each following element one unit apart.

使用低级版本的imagefunction instead, set theYDATA属性作为名称值对。例如,图片('XData',x,'YData',y,'CData',C)

You cannot interactively pan or zoom outside the x-axis limits or y-axis limits of an image, unless the limits are already set outside the bounds of the image. If the limits are already outside the bounds, there is no such restriction. If other objects (such as a line) occupy the axes and extend beyond the bounds of the image, you can pan or zoom to the bounds of the other objects, but no further.

数据类型:single|双倍的|int8|INT16|INT32|INT64|UINT8|UINT16|UINT32|uint64|logical

目的。如果您不指定object, thenimage使用当前轴。

姓名-Value Arguments

Specify optional pairs of arguments asname1 = value1,...,namen = valuen, 在哪里姓名is the argument name andValue是相应的值。名称值参数必须在其他参数之后出现,但是对的顺序并不重要。

Before R2021a, use commas to separate each name and value, and enclose姓名用引号。

例子:图片([1 2 3],'AlphaData',0.5)displays a semitransparent image.

此处列出的属性是图像属性的子集。有关完整列表,请参阅图像属性

颜色数据映射方法, specified as'direct'or'scaled'。利用this property to control the mapping of color data values inCDatainto the colormap.CDatamust be a vector or a matrix defining indexed colors. This property has no effect ifCDatais a 3-D array defining true colors.

的methods have these effects:

  • 'direct'- 将值解释为当前菌落中的索引。十进制部分的值固定在最近的下部整数上。

    • If the values are of type双倍的orsingle, then values of1or less map to the first color in the colormap. Values equal to or greater than the length of the colormap map to the last color in the colormap.

    • If the values are of typeUINT8,UINT16,UINT32,uint64,int8,INT16,INT32, orINT64, then values of0or less map to the first color in the colormap. Values equal to or greater than the length of the colormap map to the last color in the colormap (or up to the range limits of the type).

    • If the values are of typelogical, then values of0map to the first color in the colormap and values of1在菌落中映射到第二种颜色。

  • 'scaled'— Scale the values to range between the minimum and maximum color limits. The攀登property of the axes contains the color limits.

Transparency data, specified in one of these forms:

  • 标量 - 在整个图像上使用一致的透明度。

  • Array the same size asCData- 为每个图像元素使用不同的透明度值。

AlphaDataMappingproperty controls how MATLAB®interprets the alpha data transparency values.

例子:0.5

数据类型:single|双倍的|int8|INT16|INT32|INT64|UINT8|UINT16|UINT32|uint64|logical

解释AlphaData值, specified as one of these values:

  • 'none'— Interpret the values as transparency values. A value of 1 or greater is completely opaque, a value of 0 or less is completely transparent, and a value between 0 and 1 is semitransparent.

  • 'scaled'- 将值映射到图的alphamap中。轴的最小和最大α极限决定了分别映射到Alphamap中第一个和最后一个元素的alpha数据值。例如,如果alpha限制为[3 5], then alpha data values less than or equal to3映射到alphamap中的第一个元素。alpha数据值大于或等于5alphamap映射到最后一个元素。的阿里姆轴的属性包含alpha限制。的Alphamap图的属性包含alphamap。

  • 'direct'— Interpret the values as indices into the figure’s alphamap. Values with a decimal portion are fixed to the nearest lower integer:

    • If the values are of type双倍的orsingle, then values of 1 or less map to the first element in the alphamap. Values equal to or greater than the length of the alphamap map to the last element in the alphamap.

    • If the values are of type integer, then values of 0 or less map to the first element in the alphamap. Values equal to or greater than the length of the alphamap map to the last element in the alphamap (or up to the range limits of the type). The integer types areUINT8,UINT16,UINT32,uint64,int8,INT16,INT32, andINT64

    • If the values are of typelogical, then values of 0 map to the first element in the alphamap and values of 1 map to the second element in the alphamap.

输出参数

collapse all

Image对象,返回为标量。利用im创建图像后设置属性。对于列表,请参阅图像属性

More About

collapse all

High-Level Versus Low-Level Version of Image

imagefunction has two versions, the high-level version and the low-level version. If you useimagewith'cdata'作为输入参数,您正在使用低级版本。否则,您正在使用高级版本。

高级版本的imagecallsnewplotbefore plotting and sets these axes properties:

  • Layerto'top'。的image is shown in front of any tick marks or grid lines.

  • YDirto“反向”。Values along they-axis increase from top to bottom. To decrease the values from top to bottom, setYDirto'normal'。此设置扭转了y- 轴和图像。

  • 看法to[0 90]

的low-level version of theimagefunction does not callnewplotand does not set these axes properties.

提示

  • 要以各种标准格式(例如TIFF)从图形文件中读取图像数据,请使用imread。To write MATLAB image data to graphics files, useimwrite。的imreadandimwritefunctions support a variety of graphics file formats and compression schemes.

扩展功能

Version History

Introduced before R2006a