use of parallel computing function lowers quality of saved image

1 visualización (últimos 30 días)
Hi, I'm generating and saving some figures as png images, using commands along the lines of:
fig=figure('Color',[1,1,1],'Position',[0 0 1242 1679]);
set(fig,'PaperUnits','centimeters','PaperType','A4','PaperOrientation', 'portrait', 'PaperPosition', [0.63452 0.63452 21 28.41]);
(code to plot data here)
printtext = sprintf('print -dpng -r150 %s',imageName);
eval(printtext);
The figures get saved as 1242- by 1679-pixel png images, as desired, when I run the code without using the Parallel Computing Toolbox.
However, once I set the parallel computing version going, using 'parfor' loops, my images are saved with dimensions of only 596 by 806 pixels (half the desired width and height).
I've tried increasing the resolution from 150 to 300 and 600 dpi, and/or specifying a different figure size with the command fig=figure('Color',[1,1,1],'Position',[0 0 1242*2 1679*2]); to no avail.
I'm not sure how the change in environment (from non-parallel to parallel) causes this decrease in image quality, and can't find any documentation about this particular issue.
If anyone can shed light on it or offer suggestions, that'd be much appreciated.
Thanks,
Xing
  1 comentario
Jan
Jan el 21 de Feb. de 2013
Just a note: Avoid using EVAL without any reasons. This is much nicer:
print('-dpng', '-r150',imageName)

Iniciar sesión para comentar.

Respuesta aceptada

Chen Xing
Chen Xing el 22 de Feb. de 2013
Editada: Chen Xing el 22 de Feb. de 2013
Emailed technical support and received this reply:
The ability to change the print resolution when running MATLAB as a worker is not available in MATLAB 7.9. Running as a worker involves starting MATLAB with the -NoFigureWindows startup option. In this mode, MATLAB must use the Ghostscript drivers, which ignore the "-r" option when generating -djpeg, -dpng, -dtiff and -tiff image files.
As a workaround, the MATLAB worker machine should only be used to process and store data. You can then use a normal MATLAB session to generate and save the PNG images. For example, the worker machines could generate the figure and then save them to FIG files. Afterwards, a client (not worker) MATLAB machine could then be used to open and convert the FIG files like so:
%%%BEGIN CODE%%%
open('imagename.fig')
print('-djpeg','-r150','imagename.jpg')
%%%END CODE%%%
---------------------
I followed their advice and implemented it thus:
Within a parfor loop, when using the Parallel Computing Toolbox with multiple workers:
parfor i=1:100
(plot data in figure)
imageName=num2str(i);
saveas(fig,imageName,'fig')
end
After running the parfor loop, NOT using multiple workers anymore, just using a basic 'for' loop:
for i=1:100
figFileName=[num2str(i),'.fig'];
uiopen(figFileName,1)
printFileName=[num2str(i),'.png'];
print('-dpng','-r150',printFileName)
end
Works fine now!

Más respuestas (1)

Sean de Wolski
Sean de Wolski el 21 de Feb. de 2013
I can reproduce this. It is apparently somehow related to how the figures are created in headless mode.
Please contact technical support.

Categorías

Más información sobre Parallel for-Loops (parfor) en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by