saving figure in png does not work properly - matlab

I have a figure like below:
which I set the figure window to full screen with below command
figure('units','normalized','outerposition',[0 0 1 1])
but when I am trying to automatically save the figure with
print(sprintf('%s-%s-grind-compare.png', envs_{e}, methods_{m}), '-r300', '-dpng') The result would be as below:
Question: How can I fix this?

It may not be the best way, but you could save with a much higher resolution then resize the file - I believe the r300 is setting the resolution and then the font size is relative to that figure size.

Related

Matlab figure contents lost while saving as eps/pdf

I have tried most of the usually used options (print(figr, '-depsc', 'cross_corr.eps');) to save a matlab figure as eps/pdf but each time I do it, the figure contents are saved partially and perhaps one quarter of it is lost.
I have shared the figure here: http://ge.tt/2ZrsdD02/v/0?c
Using the options such as the following save it completely but I prefer it save it directly inti eps/pdf:
print(figr, '-dpng', 'cross_corr.png');
The problem seems to be that you have very small values in the 'PaperPosition' property of the figure. Try changing them to the default ones,
set(figr, 'PaperPosition', [0.634517 6.34517 20.3046 15.2284])
and then apply your print(figr, '-depsc', 'cross_corr.eps').
I attach results on my computer without and with 'PaperPosition' correction (using GSview with bounding box showed):
Also, consider reducing font size to avoid overlapped text:
set(findobj('type','text'), 'Fontsize', 5)
If I first enlarge the figure size (by using the middle button on the top right), and then save it as eps, I get this: http://ge.tt/1Pv8YE02/v/0
The quality is very nice as compared to all other options and the content are also ok.
Its not possible to automate it through script?...

How to make a montage of different-sized images

I'm trying to make a montage of figures in Matlab, each figure comprising a row - I have about 12 rows in total. I tried making the whole thing with subplot but the resolution is limited by the screensize and too low. Then I tried saving each figure as an image, using export_fig, and arranging these with subplot but again the resolution is too low. So then I tried montage, but it expects the images to be the same size and they aren't quite (height varies slightly), and export_fig doesn't seem to have the option to control the crop size. If anybody has any solutions I would be grateful!
This is my suggestion:
First resize your images to the same size.
For example,
B = imresize(A, [512 512]);
Second you can use montage or you can use imgdisp
Imgdisp gives you more options than montage. You can consider using it..

Distortion while saving matlab figure as a eps file

saveas(gcf,'result.pdf');
After I using above command to output my figure into a eps file, I got the following result.
However, the actual figure is like the following.
I have tried using other commands like
saveas(gcf, 'result.eps');
print -depsc myplot.eps
or even the 'export_fig' library,but still can't get correct figure output.
Does anyone know where is the key point of this problem? Thanks.
[ Update ]
Following dpwe's comment, after zooming in the figure, the result of .eps is like this
and the original figure is like this
Yes, it seems that they are much more similar!
The saveas function uses a default size for saving figures, I think it's something like 3/4 of your screen resolution. You can figure it out by looking at the number of pixels in the image (for a png anyway). If you run
set(gcf,'Position',[a b c d]);
saveas(gcf, 'result.eps');
to resize the figure to the size that saveas will use to save it before it saves it, that might help.

Matlab imwrite() quality

I'm very new to Matlab, though I know a few other programming languages, so please forgive me if this is something simple. I have not been able to find any answers to this, either on StackOverflow or elsewhere.
I produce a figure using the following code:
figure(6),imageplot(P); drawnow;
Which looks like this:
I then save this image to my computer using the following commands:
imwrite(P, 'images/plot.png');
And the resulting image is tiny, and missing some of the color information:
If, however, I utilize the save function in the open figure (image #1) and save it manually, I get exactly what I want, which is that exact image stored on my computer.
How would I program that? I assumed that imwrite() would just write the image directly, but apparently I'm doing something wrong. Any advice? Perhaps it has something to do with the imageplot command? I cannot seem to get that to work in imwrite.
Update: Based on the comments below, I have begun using "imresize" with the "nearest" option. This scales the image properly, but the resulting image is still curiously darker (and therefore has less information) than if I hit the "save" button in the figure.
Image saved from figure:
Image using "imresize" with "nearest" option:
The MATLAB imwrite command saves exactly the number of pixels as specified in your image matrix. This is the actual result of your computation; the reason the output is "tiny" is because it is supposed to be. To make it larger, would be to simply scale/zoom it as required.
The save figure option however does something quite different: it rasterizes the the output you obtain in the figure window and gives you the option for saving it as an image. This is evident in the fact that when you do so, you obtain a white background in addition to your result which is really just the grey background you see before you save it; this can be adjusted by resizing the figure window before utilizing the save option.
If you're looking to simply make the output figure larger, I would recommend using something along the lines of the imresize command.
Say, if you want the default size to be twice the size of the real result, simply use:
imresize(P, 2.0);
For more options, try help imresize.
The command you need for the "Save As..." functionality of figures is called "print". I often use
print(gcf, '-dpng', 'some_filename.png')
or
print(gcf, '-depsc', 'some_filename.eps','-r0')
to save a figure as it is shown on screen. The format png offers a small filesize and excellent quality, and it is understood by most image viewers and browsers. The eps format is a vector format, which I use for printig. The '-r0' option specifies "use the same size as given by the screen resolution" for the vector format properties.

how to save imageof axes for high resolution in matlab GUI

I trying save image with the comand 'getframe' but resolution is very low, so I can not give zoom. for now I'm using the code:
[arq,dir] = uiputfile('*.jpg','Output Files');
fileName=fullfile(dir,arq);
f=getframe(handles.axes1);
[x,map]=frame2im(f);
imwrite(x,fileName,'jpg');
I need save in jpg and also need save the label (x,y) in graph. How do ? There is another command better than the getframe??
Print is a good command?
Thanks
try using something other than jpg, it doesn't scale well. eps is a good choice as it is a vector format.
Try exportfig from FEX: exportfig