主要内容

imagesc

Display image with scaled colors

描述

example

imagesc(C)displays the data in arrayC作为一个image that uses the full range of colors in the colormap. Each element ofCspecifies the color for one pixel of the image. The 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

imagesc(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 letimagescdetermine the other, setxandy作为标量值。图像被拉伸并定向为适用。

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

imagesc('xdata',x,'YData',y,'CData',C)specifies the image location. This syntax is the low-level version ofimagesc(x,y,C)

imagesc(___,Name,Value)使用一个或多个名称值对参数指定图像属性。您可以在上一个语法中的任何输入参数组合之后指定名称值对参数。有关图像属性和描述的列表,请参见图像属性

example

imagesc(___,攀登)specifies the data values that map to the first and last elements of the colormap. Specify攀登as a two-element vector of the form[cmin cmax],值小于或等于CMINmap to the first color in the colormap and values greater than or equal tocmaxmap to the last color in the colormap. Specify攀登after name-value pair arguments.

imagesc(ax,___)creates the image in the axes specified byaxinstead of in the current axes (GCA)。将轴指定为第一个输入参数。

example

im= imagesc(___)returns theImageobject created. Useim创建图像后设置属性。You can specify this output with any of the input argument combinations in the previous syntaxes.

例子

collapse all

Create matrix C. Display an image of the data in C. Add a colorbar to the graph to show the current colormap. By default,imagescscales the color limits so that image uses the full range of the colormap, where the smallest value inC地图为colormap中的第一种颜色和最大的值地图到最后的颜色。

C = [0 2 4 6;8 10 12 14;16 18 20 22];imagesc(C) colorbar

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

将图像放置在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]; imagesc(x,y,C)

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

Notice that the pixel corresponding toC(1,1)is centered over the point (5,3). The pixel corresponding toC(3,4)is centered over the point (8,6).imagescpositions and orients the rest of the image between those two points.

CreateC作为数据值数组。创建图像Cand set the color limits so that values of 4 or less map to the first color in the colormap and values of 18 or more map to the last color in the colormap. Display a colorbar to show how the data values map into the colormap.

C = [0 2 4 6;8 10 12 14;16 18 20 22];攀登= [4 18];imagsc(c,攀登)配色栏

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

Create an image and return the image object,im。这n, make the image semitransparent by setting theAlphaData属性image object.

C = [1 2 3; 4 5 6; 7 8 9]; im = imagesc(C);

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

im.alphadata = .5;

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

Create a surface plot. Then, add an image under the surface.imagescdisplays the image in the xy-plane.

z = 10 +峰;冲浪(z)握住onimagsc(z)

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

Input Arguments

collapse all

Image color data, specified as a vector or a matrix. Each element ofCdefines a color for one pixel of the image. The elements ofC在相关轴的结肠中映射到颜色。最小的价值C地图为colormap中的第一种颜色和最大的值地图到最后的颜色。行为NaN元素未定义。

Note

If you specifyC作为一个m-经过-n-经过-3 array, then theimagesc函数将图像解释为trueColor(RGB)图像。imagescdoes not rescale pixel values of truecolor images. Use the恢复function to scale truecolor pixel values before callingimagesc

To use the low-level version of theimagescfunction instead, set theCData属性作为名称值对。例如,imagesc('cdata',C)

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

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

  • Two-element vector — Use the first element as the location for the center ofC(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.

To use the low-level version of theimagescfunction instead, set theXData属性作为名称值对。例如,imagesc('xdata',x,'YData',y,'CData',C)

你不能外交互式地拖动或缩放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:

  • Two-element vector — Use the first element as the location for the center ofC(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.

To use the low-level version of theimagescfunction instead, set theYData属性作为名称值对。例如,imagesc('xdata',x,'YData',y,'CData',C)

你不能外交互式地拖动或缩放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

颜色限制, specified as a two-element vector of the form[cmin cmax], 在哪里cmaxis greater thanCMIN。值Cthat are less than or equal toCMINmap to the first color in the colormap. Values greater than or equal tocmaxmap to the last color in the colormap. Values betweenCMINandcmaxlinearly map to the colormap.

如果指定颜色限制,则imagesc功能设置攀登轴的属性到指定的值。如果您不指定颜色限制,则imagescsets the攀登轴的属性达到最小值和最大值C

目的。If you do not specify anobject, thenimagesc使用当前轴。

Name-Value Arguments

Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN, 在哪里Nameis the argument name andValue是相应的值。名称值参数必须在其他参数之后出现,但是对的顺序并不重要。

Before R2021a, use commas to separate each name and value, and encloseName用引号。

例子:imagesc([1 2 3],'alphadata',0.5)displays a semitransparent image.

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

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映射到最后一个元素。这ALim属性axes contains the alpha limits. TheAlphamap图的属性包含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

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

高级版本的imagesccallsnewplotbefore 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 theimagescfunction does not callnewplotand does not set these axes properties.

For both versions, theimagescfunction sets:

  • CData属性Image反对值C

  • CDataMapping属性Imageobject to'scaled'

  • 攀登属性object to the minimum and maximum values inC, unless you specify the攀登input argument.

提示

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

  • 要查看或设置轴的颜色限制,您可以使用攀登function.在R2022a之前,使用卡克斯(R2021b)

Extended Capabilities

Version History

Introduced before R2006a