In MATLAB, how do I plot to an image and save the result without displaying it?

When you create the figure you set the Visibile property to Off.

f = figure('visible','off')

Which in your case would be

im = imread('image.tif');
f = figure('visible','off'), imshow(im, 'Border', 'tight');
rectangle('Position', [100, 100, 10, 10]);
print(f, '-r80', '-dtiff', 'image2.tif');

And if you want to view it again you can do

set(f,'visible','on')

Leave a Comment