在 MATLAB 中,如何绘制图像并保存结果而不显示它?

问题描述:

这个问题开始于这个问题 结束.MATLAB 具有强大而灵活的图像显示系统,可让您使用 imshow 和 plot 命令显示复杂图像,然后保存结果.例如:

This question kind of starts where this question ends up. MATLAB has a powerful and flexible image display system which lets you use the imshow and plot commands to display complex images and then save the result. For example:

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

这很好用.

问题在于,如果您要进行大量图像处理,那么显示您创建的每张图像就开始变得非常困难——您通常只想保存它们.我知道我可以开始直接写入图像然后保存结果.但是使用 plot/rectangle/imshow 非常简单,所以我希望有一个命令可以让我调用 plot、imshow 等,而不显示结果,然后保存本来会显示的内容.任何人都知道任何快速解决方案?

The problem is that if you are doing a lot of image processing, it starts to be real drag to show every image you create - you mostly want to just save them. I know I could start directly writing to an image and then saving the result. But using plot/rectangle/imshow is so easy, so I'm hoping there is a command that can let me call plot, imshow etc, not display the results and then save what would have been displayed. Anyone know any quick solutions for this?

或者,一种将样条曲线放到位图上的快速方法可能会奏效...

Alternatively, a quick way to put a spline onto a bitmap might work...

创建图形时,将 Visibile 属性设置为 Off.

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

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

在你的情况下是什么

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')