How can I write text on a JPG and save it without displaying (R2010b)

8 views (last 30 days)
Hello,
I have an image (jpg) and I want to add text in it without showing anything on the screen. I followed this link (the first part, with the "tmask" stuff) but it pop up the text. I'm on Matlab 2010b so the function inserText is not available.
Thanks, Valentin

Accepted Answer

Image Analyst
Image Analyst on 19 Jan 2016
I don't know of any other way to do it without displaying the image.
If you can tolerate displaying it, you can use export_fig() by Yair Altman in the File Exchange. Use text() to put your text and any other graphics in the overlay, then use export_fig() to save it to a file.
Is getting a more modern version with that toolbox completely out of the question?
  1 Comment
Valentin Debris
Valentin Debris on 19 Jan 2016
Edited: Valentin Debris on 19 Jan 2016
I find a way using export_fig(), and it doesn't display the figure. It's not perfect (it resizes a little the image) but for my case, I don't care.
im = imread('C:\Users\Users\Downloads\losange.jpg');
hf = figure('color','white','Visible','Off');
set(gca,'units','pixels','position',[5 5 size(im,2)-1 size(im,1)-1],'Visible','Off')
%display the image in the figure
image(im)
axis off;
hold on;
%put the text
text('units','pixels','position',[10 20],'fontsize',15,'string','test1');
%get the final image based on the axe
%export_fig is developped by Yair Altman (in the File Exchange)
imageWithTxt = export_fig(findobj(hf,'type','axes'));
%save the image
imwrite(imageWithTxt ,'losangeTxt.jpg');

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!