插入
在图像或视频中插入文字
句法
Description
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)('木板');
我nsert Numeric Text on Image
阅读图像。
我= 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(“数字值”);
输入参数
我
-输入图像
m-by-n-by-3 trueColor|m-by-n2-D grayscale image
输入图像,,,,specified asm-by-n-by-3 TrueColor图像or anm-by-n2-D grayscale image.
Data Types:single
|double
|int16
|uint8
|uint16
文本
-Unicode文本字符向量
character vector|字符串标量|细胞array of character vectors|字符串数组
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
位置
-Position of inserted text
vector|矩阵
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 enclosename
in quotes.
Example:“锚点”
,,,,'左图'
字体
-字体face of text
'lucidasansregular'
(default) |character vector
文本的字体面,指定为逗号分隔对,由'字体
'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
字体大小
-字体大小
12
(default) |正整数在范围内[1,200]
字体尺寸,指定为逗号分隔对'
字体大小
'
and a positive integer in the range [1,200].
Data Types:double
|single
|int8
|int16
|int32
|int64
|uint8
|uint16
|uint32
|uint64
textcolor
-Text color
'black
'(default) |character vector|细胞array of character vectors|[R G B]矢量|m-by-3矩阵
文本颜色,指定为逗号分隔对,由'
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, set
textcolor
to a cell array ofm颜色角色向量的数量。或者,您可以将其设置为m-by-3矩阵of RGB character vector color values.To specify one color for all text character vectors, set
textcolor
到红色,绿色和蓝色值的颜色角色向量或[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
盒子
-文本框颜色
'黄色
'(default) |character vector|细胞array of character vectors|[R G B]矢量|m-by-3矩阵
文本框颜色,指定为逗号分隔对,由'
盒子
'
以及字符矢量,字符矢量的单元格数或矩阵。您可以为每个文本框指定不同的颜色,也可以为所有框指定一种颜色。
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
拳击
-文本框的不透明度
0.6(default) |标量值在[0
1
这是给予的
文本框的不透明度,指定为逗号分隔对,由'拳击
'and a scalar value in the range [0,1]. A value of0
对应于一个完全透明的文本框,或没有框。一个值1
corresponds to a fully opaque text box.
Data Types:double
|single
|int8
|int16
|int32
|int64
|uint8
|uint16
|uint32
|uint64
锚点
-文本框参考点
'左图
'(default) |'LeftCenter
'|'LeftBottom
'|'中心
'|'中心
'|'中心Bottom
'|'RightTop
'|'RightCenter
'|'RightBottom
'
文本框参考点,指定为逗号分隔对,由'锚点
'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
RGB
-Output image
m-by-n-by-3 TrueColor图像
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
C/C++ Code Generation
使用MATLAB®CODER™生成C和C ++代码。
Usage notes and limitations:
字体
,,,,字体大小
必须是编译时常数。non-ASCII characters are not supported.
版本历史记录
mATLAB 명령
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
Matlab명령명령명령에입력하십시오하십시오하십시오하십시오하십시오하십시오。Matlab명령명령을지원않습니다않습니다않습니다않습니다。
选择一个网站
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:。
您还可以从以下列表中选择一个网站:
How to Get Best Site Performance
选择中国网站(中文或英语)以获得最佳场地性能。其他Mathworks乡村网站未针对您所在的访问进行优化。
美洲
- América Latina(Español)
- 加拿大(English)
- 美国(English)
欧洲
- netherlands(English)
- 挪威(English)
- Österreich(德意志)
- 葡萄牙(English)
- Sweden(English)
- 瑞士
- United Kingdom(English)