如何不间断的引用Matlab的imagesc?

How to Take Reference of Matlab's imagesc without Interruption?

线程的测试代码 其中 returns 两个字段的结构 cdatacolormap 其中 cdata 是图形的 RGB 表示

hFig=figure;
imagesc(time, potential, matrix); % choose any data

%% Test Code Starts
fr = getframe(hFig);
rgbImage = fr.cdata;
figure  
imshow(rgbImage) 
colormap parula 
%% Test Code ends

saveas(hFig, '/home/masi/image.eps', 'eps');

输出

预期输出:saveas 在磁盘上并在屏幕上显示对象的引用。不理解引用imagesc对象导致的中断。

export_fig

Suever 的提议。我成功关注 here

filenamePng=fullfile('/home/masi/image.png'); 
export_fig(filenamePng, '-png', hFig); % works with right resolution
export_fig(filenamePng, '-png', '-q101', hFig ); % works
export_fig(filenamePng, '-png', '-native', hFig);  % works but reduced resolution i.e. your screen resolution of 72 dpi here
export_fig(filenamePng, '-png', '-q101', '-native', hFig);  % works but reduced resolution

filename=fullfile('/home/masi/image'); 
% '-depsc' uses eps-3 so avoiding Matlab's buggy eps-2
% '-nocrop' for no cropping of the data
% '-a1' no anti-aliasing because we do not need it
export_fig(filename, '-png', '-eps', '-depsc', '-nocrop', '-q101', '-a1', hFig); % works 
% results in 0.6 MB image

% '-opengl' results in 12 MB image and aliasing so incomplete vectorisation in Matlab  
export_fig(filename, '-png', '-eps', '-depsc', '-nocrop', '-opengl', ...
    '-q101', hFig); % works 
% have -a1, much alias, 12 MB 
% have -a4, much alias, 34 MB and warning `Warning: print2array generating a 33.2M pixel image. This could be slow and might also cause memory problems.`

所以不要在 Matlab 中使用 -opengl。另外,想想你是否可以在 Matlab 中可靠地使用所有 .eps。 [Suever, Masi]

系统:Linux Ubuntu 16.04 64 位
硬件:Macbook Air 2013 年中期
Linux内核:4.6
Linux 内核选项:wl
Matlab:2016a

我怀疑在您的机器上将图像保存为 EPS 文件时出现问题。 MATLAB 因创建错误的 EPS 文件而臭名昭著,如果您真的想使用 EPS 文件,我建议您使用 export_fig from the MATLAB File Exchange.

此外,如果您要导出到 EPS,建议不要使用 opengl 渲染器,因为这通常会导致非常大的 EPS 文件"vectorized" 不正确。

话虽这么说,但在这种情况下使用 EPS 并没有真正让您受益匪浅。 由于您本质上是截取图像,然后使用 imshow 显示此屏幕截图,因此您已经失去了初始图像的很多质量。相反,对于光栅数据,您可以使用无损图像格式(如 PNG)来保存数据,另外一个好处是 MATLAB 在生成 PNG 文件时更加可靠。

也可能值得使用 imwrite 而不是 imshow + saveas 来保存图像。

imwrite(fr.cdata, 'output.png')