Insert text in image.
This function inserts the specified text into the given image at the specified position. The function returns a modified image with text annotation.
Inputs
An MxN array representing a grayscale image or an MxNx3 array representing an RGB image where text will be inserted.
An Nx2 array specifying the (x, y) coordinates for each text annotation. Each row corresponds to a position for a text string in the image.
A cell array of strings containing the text to be inserted at each specified position. The number of strings must match the number of positions.
Numerical values to be inserted at each specified position. The number of strings must match the number of positions.
Additional name-value pair arguments to control text properties such as ’Font’, ’FontSize’, ’FontColor’ / ’TextColor’, ’TextBoxColor’, ’BoxOpacity’, ’AnchorPoint’.
Name-Value Pair Arguments
A string specifying the font name. Default is "LucidaSansRegular"
A positive number specifying the font size of the text. Default is 12.
A 1x3 RGB vector specifying the color of the text. Default is [0, 0, 0] (black). For grayscale images, the color will be converted to a corresponding grayscale intensity.
A 1x3 RGB vector specifying the color of the text box. Default is [1, 1, 1] (white). For grayscale images, the color will be converted to a corresponding grayscale intensity.
A scalar between 0 and 1 specifying the opacity of the text box. Default is 0.6.
A string specifying which part of the text box is anchored to the position. Options include ’LeftTop’, ’LeftCenter’, ’LeftBottom’, ’CenterTop’, ’Center’, ’CenterBottom’, ’RightTop’, ’RightCenter’, ’RightBottom’. Default is ’LeftTop’.
Outputs
An MxNx3 array for an RGB image representing the modified image with text annotations.
Example
image = imread('example.jpg'); position = [50, 100; 150, 200]; text = {'Hello', 'World'}; outputImage = insertText(image, position, text, 'FontSize', 20, 'TextColor', [1, 0, 0], 'AnchorPoint', 'Center'); imshow(outputImage);
See also: text, imshow, imread.
Package: image