temp
temp

Reputation: 265

How to insert numeric text into the image?

I'm using R2011a Matlab version.I need to insert numeric values on image.
I referred this link, but in that link,they only mentioned how to insert text on the image.
This answer is also not working for my Matlab version.

Can somebody please help me?

Upvotes: 2

Views: 139

Answers (1)

Shai
Shai

Reputation: 114786

First of all, text and numeric values are not differetnt: you can convert any numeric value into a text (string) using sprintf:

 numeric = 10.453;
 as_text = sprintf('%.3f', numeric);

Now you have a text '10.453' you can put on the image.


Alternatively, you can

 img = imread('football.jpg');
 fh = figure;
 imshow(img, 'border', 'tight');
 text( 'Position', [30, 50, 0], 'String', sprintf('%.3f', numeric), 'Color', 'w');

You get:
enter image description here

See text for more information and options for formatting the text on top of the image.

If you want to actually save the altered pixel values (representing the text on top of the image) you can capture the figure using getframe:

fr = getframe(fh);
image_with_text = fr.cdata;

Upvotes: 1

Related Questions