use of parallel computing function lowers quality of saved image

조회 수: 1 (최근 30일)
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
Jan
Jan 2013년 2월 21일
Just a note: Avoid using EVAL without any reasons. This is much nicer:
print('-dpng', '-r150',imageName)

댓글을 달려면 로그인하십시오.

채택된 답변

Chen Xing
Chen Xing 2013년 2월 22일
편집: Chen Xing 2013년 2월 22일
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!

추가 답변 (1개)

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

카테고리

Help CenterFile Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by