Test code for the thread Why this imagesc-imshow with Colormap not Working in Matlab? which returns a structure of two fields cdata
and colormap
where cdata
is an RGB representation of the figure
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');
Output
- without test code,
saveas
successful - with test code,
saveas
fails with blank output and you get successfully figure output on your screen
Expected output: saveas
on the disk and show reference of the object on the screen. I do not understand the interruption caused by taking the reference of the imagesc
object.
To export_fig
Suever's proposal. I do successfully following 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.`
So do not use -opengl
in Matlab. Also, think if you can use at all .eps reliably in Matlab. [Suever, Masi]
- Without
-opengl
, is the rendering vectorised properly with-depsc
? The size of the file is significantly smaller without noticebly aliasing. TODO test yourself. Ticket here.
System: Linux Ubuntu 16.04 64 bit
Hardware: Macbook Air 2013-mid
Linux kernel: 4.6
Linux kernel options: wl
Matlab: 2016a