Insert text into image without computer vision toolbar - Matlab

In Matlab Center ( http://www.mathworks.com/matlabcentral/answers/26033-how-to-insert-text-into-image ) I found this code:

Text = sprintf('Create text inserter object \nwith same property values');
H = vision.TextInserter(Text);
H.Color = [1.0 1.0 0];
H.FontSize = 20;
H.Location = [25 25];
I = im2double((imread('football.jpg')));
InsertedImage = step(H, I);
imshow(InsertedImage);

      

How can I do the same without using the CCTV toolbar?

thank

+3


source to share


2 answers


To follow up on my comment:

A = imread('football.jpg');

YourText = sprintf('Create text inserter object \nwith same property values');

figure;

imshow(A);

hText = text(25,25,YourText,'Color',[1 1 0],'FontSize',20);

      

Providing the following:

enter image description here



Take a look at the document page to see all the options available to change / customize your text. Note that you do not need to use the sprintf

string to generate, however, you must use the newline character ( \n

) internally to work with it sprintf

.

EDIT In response to your comment below, if you need to save an image with text embedded in it, you can use getframe to get the content of the image, and then imwrite to save it:

hFrame = getframe(gca) %// Get content of figure

imwrite(hFrame.cdata,'MyImage.tif','tif') %// Save the actual data, contained in the cdata property of hFrame

      

EDIT # 2 As an alternative to usage getframe

, take a look here as there are 2 suggested ideas, i.e. using saveas or avi files.

+4


source


The answer above (Benoit_11) requires that you first display the image, write the text, and then save the image. This is very slow if you are processing frames of the video (not one or more images). To get much faster processing times, you need to write directly to the image matrix. One option I can think of (but it's not very elegant) is to create (or download) small templates for alphabet characters (e.g. 20x20) and then rewrite the image matrix in the desired area with those templates. For example, for an RGB image "true color" we will have something like this:



im(y:y+19,x:x+19,:)=template;

0


source







All Articles