我的目标是:
因此,我正在运行以下代码:
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
在隐形人物中显示图像,而不是试图弹出?
答案 0 :(得分:1)
这样可行,
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()函数
答案 1 :(得分:0)
当我在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
答案 2 :(得分:0)
对于任何降落在这里的人。在努力解决这个问题后,我设法从mathworks获得了支持。 解决方案很简单。您还需要将轴可见性设置为关闭。
E.g。
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');