-2

线程的测试代码为什么这个带有 Colormap 的 imagesc-imshow 在 Matlab 中不起作用?它返回两个字段的结构,cdata其中colormapcdata图形的 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成功
  • 使用测试代码,saveas以空白输出失败,您在屏幕上成功获得图形输出

预期输出:saveas在磁盘上并在屏幕上显示对象的引用。我不明白由于引用imagesc对象而引起的中断。

export_fig

苏弗的提议。我确实成功地关注了这里

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.`

所以不要-opengl在Matlab中使用。另外,想想你是否可以在 Matlab 中可靠地使用 .eps。[苏弗,马西]

  • 没有-opengl,渲染是否用 正确矢量化了-depsc?文件的大小明显更小,没有明显的锯齿。TODO 测试自己。票在这里

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

4

1 回答 1

1

我怀疑在您的机器上将图像保存为 EPS 是一个问题。MATLAB 因创建不良 EPS 文件而臭名昭著,如果您真的想使用 EPS 文件,我建议使用export_figMATLAB File Exchange

此外,如果您要导出到 EPS,建议不要使用 opengl 渲染器,因为这通常会导致无法正确“矢量化”的非常大的 EPS 文件。

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

此外,它可能值得使用imwrite而不是imshow+saveas来保存图像。

imwrite(fr.cdata, 'output.png')
于 2016-07-08T13:30:48.117 回答