Table of Contents
qc_draw_text
Draws text directly on an image rather than using a figure window or axes.
im_out = qc_draw_text(im, font, text, r, c, ...) % Draw text on an image
Draws text directly on an image. The output image will be a copy of the input image with the text drawn on it.
im
A grayscale (HxW) or RGB (HxWx3) image as a uint8 array.
font
A structure defining the font to use. The structure has the following optional fields. If a field is omitted then a suitable default is used.
Field Name |
Description |
---|---|
height |
The height of the font in pixels. |
width |
The width of the font in pixels. |
escapement |
The escapement angle in degrees (may be fractional). |
orientation |
The orientation angle in degrees (may be fractional). |
weight |
The font weight (1.0 = normal, smaller is thinner, larger is bolder, 1.75 is standard bold, 2.5 is maximum weight). |
italic |
Whether to make the font italic (true or false). |
underline |
Whether to underline the font (true or false). |
strikeout |
Whether to strike out the font (true or false). |
character_set |
A string indicating the character set to use. Valid values are: 'default', 'ansi', 'baltic', 'chinesebig5', 'easteurope', 'gb2312', 'greek', 'hangul', 'mac', 'oem', 'russian', 'shiftjis', 'symbol', 'turkish', 'vietnamese', 'johab', 'arabic', 'hebrew', 'thai'. |
output_precision |
A string indicating the output precision. Valid values are: 'default', 'character', 'device', 'outline', 'ps_only', 'raster', 'string', 'stroke', 'tt_only', 'tt'. |
clip_precision |
A string indicating the clip precision. Valid values are: 'default', 'character', 'stroke'. |
quality |
A string indicating the quality. Valid values are: 'antialiased', 'cleartype', 'default', 'draft', 'nonantialiased', 'proof'. |
pitch |
A string indicating the pitch. Valid values are: 'default', 'fixed', 'variable'. |
family |
A string indicating the family. Valid values are: 'decorative', 'dontcare', 'modern', 'script', 'swiss'. |
face |
A string containing the name of the font face to use e.g. 'Times New Roman'. |
text
A string containing the text to draw.
r
The row in pixels at which to place the origin of the text drawn.
c
The column in pixels at which to place the origin of the text drawn.
*
The function may take additional property/value pairs as arguments. Valid properties are:
Property |
Description |
---|---|
'horizontal-align' |
The horizontal alignment of the text relative to the (r,c) position. Valid values are: 'left', 'center', 'right'. |
'vertical-align' |
The vertical alignment of the text relative to the (r,c) position. Valid values are: 'bottom', 'baseline', 'top'. |
'color' |
The foreground color of the text. The value is a 3-vector containing the red, green and blue components i.e. [red, green, blue] where each component must lie in the range 0 to 255. |
'background-color' |
The background color of the text. The value is a 3-vector containing the red, green and blue components i.e. [red, green, blue] where each component must lie in the range 0 to 255. If no background color is specified then the background is transparent. |
im_out
The output image with the text drawn on it. It will have the same dimensions as the input image.
im = imread(fullfile(qc_root, 'blocks', 'command_prompt.jpg')); font.height = 20; % make text 20 pixels high im_out = qc_draw_text(im, font, 'Hello world', size(im,1)/2, size(im,2)/2, 'horizontal-align', 'center', 'color', [255 255 0]); % Draw centered yellow text imshow(im_out);
Copyright ©2024 Quanser Inc. This page was generated 2024-10-17. Submit feedback to Quanser about this page.
Link to this page.