main Content

插入

在图像或视频中插入文字

Description

例子

RGB= insertText(,,,,位置,,,,文本returns a truecolor image with文本插入。输入图像,,可以是TrueColor或灰度图像。

例子

RGB= insertText(,,,,位置,,,,数字值返回带有数字值插入的TrueColor图像。

RGB= insertText(___,,,,名称,价值使用一个或多个指定的其他选项名称,价值pair arguments.

Examples

全部收缩

阅读图像。

我= imread('board.tif');

创建包含分数的文本。

文本_str = cell(3,1); conf_val = [85.212 98.76 78.342];为了ii=1:3 text_str{ii} = ['信心: 'num2str(conf_val(ii),'%0.2f''%'这是给予的;结尾

定义文本框的位置和颜色。

位置= [23 373; 35 185; 77 107];box_color = {'红色的',,,,'绿色',,,,'yellow'};

用新的字体大小,框颜色,不透明度和文本颜色插入文本。

rgb = insertText(i,位置,text_str,'字体大小',,,,18,'盒子',,,,。。。box_color,“拳击”,0.4,'textcolor',,,,'白色的');

Display the image.

图IMShow(RGB)标题(RGB)('木板');

图包含一个轴对象。带有标题板的轴对象包含类型图像的对象。

阅读图像。

我= imread('peppers.png');

定义(X,_y_)文本和值的位置。

位置= [1 50;100 50];值= [555 pi];

我nsert text using the bottom-left as the anchor point.

RGB = insertText(我位置值,“锚点”,,,,'LeftBottom');

Display the image with the numeric text inserted.

figure imshow(RGB),title(“数字值”);

图包含一个轴对象。带有标题数值的轴对象包含类型图像的对象。

显示非ASCII字符(U+014C)

OWithMacron=native2unicode([hex2dec('C5')hex2dec('8C'),,,'UTF-8');RGB= insertText(RGB,,,,[256 50],OWithMacron,'字体',,,,'lucidasansregular',,,,'盒子',,,,'W');

Display the image with the numeric text inserted.

figure imshow(RGB),title(“数字值”);

图包含一个轴对象。带有标题数值的轴对象包含类型图像的对象。

输入参数

全部收缩

输入图像,,,,specified asm-by-n-by-3 TrueColor图像or anm-by-n2-D grayscale image.

Data Types:single|double|int16|uint8|uint16

Unicode text, specified as a single UNICODE text string or a cell array of UNICODE strings of lengthm,,,,wherem是行中的数量位置。这function overwrites pixels with the value of文本。这length of the cell array must equal the number of rows in the位置矩阵。如果指定一个字符串,则该函数将其用于位置矩阵。most unicode fonts contain ASCII characters. You can display non-English and English characters, including English numeric values, with a single font.

Data Types:single|double|int8|int16|int32|int64|uint8|uint16|uint32|uint64

数字值文本,指定为标量或向量。如果指定标量值,则该值用于所有位置。向量长度必须等于位置矩阵。numeric values are converted to a character vector using theSprintf为了mat '%0.5G'。

Data Types:char

Position of inserted text, specified as a vector or anm-by-2 matrix of [Xy]坐标。每行代表[Xy]协调锚点文本边界框。

Data Types:single|double|int8|int16|int32|int64|uint8|uint16|uint32|uint64

名称值参数

将可选的参数对name1=Value1,...,NameN=ValueN,,,,wherename是参数名称和价值is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclosenamein quotes.

Example:“锚点”,,,,'左图'

文本的字体面,指定为逗号分隔对,由'字体'and a character vector. The font face must be one of the available truetype fonts installed on your system. To get a list of available fonts on your system, typeListTruetyPefonts在Matlab®命令提示符。

Data Types:char

字体尺寸,指定为逗号分隔对'字体大小'and a positive integer in the range [1,200].

Data Types:double|single|int8|int16|int32|int64|uint8|uint16|uint32|uint64

文本颜色,指定为逗号分隔对,由'textcolor'and a character vector, cell array of character vectors, or matrix. You can specify a different color for each character vector or one color for all character vectors.

  • To specify a color for each text character vector, settextcolorto a cell array ofm颜色角色向量的数量。或者,您可以将其设置为m-by-3矩阵of RGB character vector color values.

  • To specify one color for all text character vectors, settextcolor到红色,绿色和蓝色值的颜色角色向量或[R G B]矢量。

  • RGBvalues must be in the range of the image data type. Supported colors:'blue',,,,'绿色',,,,'红色的',,,,'青色',,,,'magenta',,,,'yellow',,,,'black', 和'白色的'

Data Types:细胞|char|uint8|uint16|int16|double|single

文本框颜色,指定为逗号分隔对,由'盒子'以及字符矢量,字符矢量的单元格数或矩阵。您可以为每个文本框指定不同的颜色,也可以为所有框指定一种颜色。

  • To specify a color for each text box, set盒子to a cell array ofm颜色角色向量的数量。或者,您可以将其设置为m-by-3矩阵ofmnumber of RGB (red, green, and blue) character vector color values.

  • 要为所有文本框指定一种颜色,请设置盒子to either a color character vector or an [R G B] vector. The [R G B] vector contains the red, green, and blue values.

  • RGBvalues must be in the range of the image data type. Supported colors:'blue',,,,'绿色',,,,'红色的',,,,'青色',,,,'magenta',,,,'yellow',,,,'black', 和'白色的'

Data Types:细胞|char|uint8|uint16|int16|double|single

文本框的不透明度,指定为逗号分隔对,由'拳击'and a scalar value in the range [0,1]. A value of0对应于一个完全透明的文本框,或没有框。一个值1corresponds to a fully opaque text box.

Data Types:double|single|int8|int16|int32|int64|uint8|uint16|uint32|uint64

文本框参考点,指定为逗号分隔对,由'锚点'and a character vector value. The anchor point defines a relative location on the text box. You can position the text box by placing its anchor point at the [X,,,,y]由相应定义的坐标位置为了the text. For example, to place the center of the text box to be at the [X,,,,y这是给予的coordinate you specified with the位置输入,然后设置锚点to中心

Supported positions are左图,,,,LeftCenter,,,,LeftBottom,,,,中心,,,,中心,,,,中心Bottom,,,,RightTop,,,,RightCenter, 和RightBottom

Data Types:char

Output Arguments

全部收缩

Output image, returned as anm-by-n-by-3 trueColor图像,带有指定的文本。

限制

  • 如果您在输出图像中看不到字符,则意味着字体不包含字符。选择其他字体。要获取系统上可用字体的列表,请在MATLAB提示下键入ListTruetyPefonts

  • 增加字体大小还会增加预处理时间和内存使用量。

  • 插入function does not work for certain composite characters. For example, you cannot insert text when the rendering of one glyph corresponding to a character code influences the position, shape, or size of the adjacent glyph.

Extended Capabilities

版本历史记录

在R2013a中引入