Main Content

图像对象及其属性

图像CDATA

笔记

图片andImagesc命令创建图像对象。图像对象是cHildren of axes objects, as are line, patch, surface, and text objects. Like all graphics objects, the image object has a number of properties you can set to fine-tune its appearance on the screen. The most important properties of the image object with respect to appearance areCData,,,,cdatamapping,,,,XDATA,,,,andYDATA。这se properties are discussed in this and the following sections. For detailed information about these and all the properties of the image object, see图片

CData图像对象的属性包含数据阵列。在以下命令中,H是由图像对象创建的句柄图片和矩阵Xandyare the same:

h =图像(x);colormap(map) Y = get(h,'CData');

维度的维度CDataarray controls whether the image displays using colormap colors or as an RGB image. If theCData数组是two-dimensional, the image is either an indexed image or an intensity image; in either case, the image is displayed using colormap colors. If, on the other hand, theCData数组是m-by-n-by-3, it displays as a truecolor image, ignoring the colormap colors.

图像cdatamapping

cdatamapping属性控制图像是否是索引orintensity。显示索引图像设置cdatamapping财产为'direct',使得CData阵列直接用作图形的菌落中的指标。当。。。的时候图片command is used with a single input argument, it sets the value ofcdatamapping'direct'

h =图像(x);colormap(地图)get(h,'cdatamapping')ans =直接

Intensity images are displayed by setting thecdatamapping财产为“缩放”。在这种情况下,CData值线性缩放以形成colormap指数。轴CLimproperty controls the scale factors. TheImagescfunction creates an image object whosecdatamappingproperty is set to“缩放”,,,,and it adjusts theCLimproperty of the parent axes. For example:

h = imagesc(i,[0 1]);colormap(map)get(h,'cdatamapping')ans =缩放get(gca,'clim')ans = [0 1]

XDATA和YDATA

XDATAandYDATAproperties control the coordinate system of the image. For anm-by-n图片,,,,the defaultXDATA[1 n]and the defaultYDATA[1 m]。这些设置意味着以下内容:

  • 这left column of the image has anX-coordinate of 1.

  • 图像的正确列有一个X-coordinate ofn。

  • 这至p row of the image has ay-coordinate of 1.

  • 图像的底部有一个y-coordinate ofm。

Coordinate System for Images

Use Default Coordinate System

Display an image using the default coordinate system. Use colors from theColorcube地图。

C = [1 2 3 4; 5 6 7 8; 9 10 11 12]; im = image(C); colormap(colorcube)

图包含一个轴对象。轴对象包含类型图像的对象。

Specify Coordinate System

Display an image and specify the coordinate system. Use colors from theColorcube地图。

C = [1 2 3 4; 5 6 7 8; 9 10 11 12]; x = [-1 2]; y = [2 4]; figure image(x,y,C) colormap(colorcube)

图包含一个轴对象。轴对象包含类型图像的对象。

将文本添加到图像数据

此示例显示了如何使用数组索引将文本栅格化为现有图像。

Draw the text in an axes using the文本功能。然后,使用getframeand close the figure.

无花果=图;t = text(.05,.1,'Mandrill Face',,,,'字体大小',20,'fontchight',,,,'大胆的');F = GetFrame(GCA,[10 10 200 200]);关闭(无花果)

Select any plane of the resulting RGB image returned bygetframe。找到黑色的像素(黑色为0),并使用其下标转换为索引sub2ind。使用这些下标将文本“绘制”到包含的图像中曼德里尔垫子。使用该图像的大小以及文本的行和列位置来确定新图像中的位置。索引成新图像,替换像素。

c = F.cdata(:,:,1); [i,j] = find(c==0); load曼德里尔ind = sub2ind(size(X),i,j); X(ind) = uint8(255);

使用骨骼结肠显示新图像。

Imagesc(X) colormap

图包含一个轴对象。轴对象包含类型图像的对象。

Additional Techniques for Fast Image Updating

提高利率CDataproperty of an image object updates, optimizeCData并设置一些相关的图形和轴属性:

  • 使用可能的最小数据类型。用一个UINT8图像的数据类型比使用双倍的数据类型。

    Part of the process of setting the image'sCData属性包括复制图像使用的矩阵。矩阵的整体大小取决于其各个元素的大小。使用较小的单个元素(即,较小的数据类型)可降低矩阵的大小,并减少复制矩阵所需的时间。

  • 使用最小的可接受矩阵。

    If the speed at which the image is displayed is your highest priority, you may need to compromise on the size and quality of the image. Again, decreasing the size reduces the time needed to copy the matrix.

  • Set the limit mode properties (XLimModeandyLimMode)轴手动的

    If they are set toauto,然后每次对象(例如图像,线路,补丁等)更改其数据的某些方面时,轴都必须重新计算其相关属性。例如,如果指定

    图像(第一图);set(gca,'xlimmode',“手动”,...'ylimmode',“手动”,...“ zlimmode”,“手动”,...'climmode','Manual',“手动”,...'alimmode','手动的');

    在重新绘制图像之前,轴不会重新计算任何极限值。

  • Consider using a电影对象如果您的任务的要点是简单地在屏幕上显示一系列图像。

    这MATLAB®电影对象直接利用基础系统图形资源,而不是执行MATLAB对象代码。这比重复设置图像的速度快CData属性,如前所述。