Linux下MATLAB中不可见图形的显示
我的目标是:Linux下MATLAB中不可见图形的显示,linux,matlab,matlab-figure,Linux,Matlab,Matlab Figure,我的目标是: 创造一个看不见的形象 使用子图,在其上绘制图像,然后 保存它而不必打开它 因此,我运行以下代码: f = figure('Visible', 'off'); subplot(2, 2, 1), imshow(image1); subplot(2, 2, 2), imshow(image2); subplot(2, 2, 3), imshow(image3); subplot(2, 2, 4), imshow(image4); saveas(f, 'filename'); 但我得到
f = figure('Visible', 'off');
subplot(2, 2, 1), imshow(image1);
subplot(2, 2, 2), imshow(image2);
subplot(2, 2, 3), imshow(image3);
subplot(2, 2, 4), imshow(image4);
saveas(f, 'filename');
但我得到了一个错误:
Error using imshow (line xxx)
IMSHOW unable to display image.
这意味着imshow正在尝试显示图像。有没有办法让imshow
在不可见的图形中显示图像,而不尝试弹出?这样可以
f = figure('Visible', 'off');
subplot(2, 2, 1), image(image1);
subplot(2, 2, 2), image(image2);
subplot(2, 2, 3), image(image3);
subplot(2, 2, 4), image(image4);
saveas(f, 'filename');
In case of gray scale images
f = figure('Visible', 'off');
subplot(2, 2, 1), image(image1),colormap(gray);
subplot(2, 2, 2), image(image2),colormap(gray);
subplot(2, 2, 3), image(image3),colormap(gray);
subplot(2, 2, 4), image(image4),colormap(gray);
saveas(f, 'filename');
imagesc()也可以用来代替image()函数当我在nodisplay模式下运行Matlab时,我得到了相同的错误。我的解决方法是使用图像作为纹理贴图绘制曲面网格:
function varargout = imshow_nodisp(im)
% An IMSHOW implementation that works even when Matlab runs -nodisplay.
%
% Only we don't scale the figure window to reflect the image size. Consequently
% the ugly pixel interpolation is directly apparent. IMSHOW has it too, but it
% tries to hide it by scaling the figure window at once.
%
% Input arguments:
% IM HxWxD image.
%
% Output arguments:
% HND Handle to the drawn image (optional).
%
[h,w,~] = size(im);
x = [0 w; 0 w] + 0.5;
y = [0 0; h h] + 0.5;
z = [0 0; 0 0];
hnd = surf(x, y, z, flipud(im), 'FaceColor','texturemap', 'EdgeColor','none');
view(2);
axis equal tight off;
if nargout > 0
varargout = hnd;
end
end
对于任何登陆这里的人。在与之斗争之后,我设法从mathworks获得了支持。 解决办法很简单。还需要将轴可见性设置为“禁用” 例如
f=图形(“可见”、“关闭”);
a=轴(“可见”、“关闭”);###值得一提的是,以上内容在我的Windows机器上运行得很好。谢谢Amro。通过各种论坛搜索,我知道这可以在Windows上运行,但我真的很有兴趣在Linux上运行。我想你可以在MathWorks上提交一个文件。你使用的是什么版本的MATLAB?您的代码在我的Linux机器上也运行良好。您好,我正在使用MatlabR2011B。
f = figure('Visible', 'off');
a = axes('Visible','off'); ### <-- added this line of code
subplot(2, 2, 1), imshow(image1);
subplot(2, 2, 2), imshow(image2);
subplot(2, 2, 3), imshow(image3);
subplot(2, 2, 4), imshow(image4);
saveas(f, 'filename');