图像对象及其属性
图像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
是由图像对象创建的句柄图片
和矩阵X
andy
are the same:
h =图像(x);colormap(map) Y = get(h,'CData');
维度的维度CData
array 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指数。轴CLim
property controls the scale factors. TheImagesc
function creates an image object whosecdatamapping
property is set to“缩放”
,,,,and it adjusts theCLim
property 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
这XDATA
andYDATA
properties 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文本
功能。然后,使用getframe
and 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
提高利率CData
property of an image object updates, optimizeCData
并设置一些相关的图形和轴属性:
使用可能的最小数据类型。用一个
UINT8
图像的数据类型比使用双倍的
数据类型。Part of the process of setting the image's
CData
属性包括复制图像使用的矩阵。矩阵的整体大小取决于其各个元素的大小。使用较小的单个元素(即,较小的数据类型)可降低矩阵的大小,并减少复制矩阵所需的时间。使用最小的可接受矩阵。
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 (
XLimMode
andyLimMode
)轴手动的
。If they are set to
auto
,然后每次对象(例如图像,线路,补丁等)更改其数据的某些方面时,轴都必须重新计算其相关属性。例如,如果指定图像(第一图);set(gca,'xlimmode',“手动”,...'ylimmode',“手动”,...“ zlimmode”,“手动”,...'climmode','Manual',“手动”,...'alimmode','手动的');
在重新绘制图像之前,轴不会重新计算任何极限值。
Consider using a
电影
对象如果您的任务的要点是简单地在屏幕上显示一系列图像。这MATLAB®
电影
对象直接利用基础系统图形资源,而不是执行MATLAB对象代码。这比重复设置图像的速度快CData
属性,如前所述。