2

I've got a ~1600 line program that reads in images (either tiff or raw), performs a whole bunch of different mathematical and statistical analyses, and then outputs graphs and data tables at the end.

Almost two-thirds of my processing time is due to looping 16 times over the following code:

h = figure('Visible','off','units','normalized','outerposition',[0 0 1 1]);
set(h,'PaperPositionMode','auto');
imagesc(picdata); colormap(hot);
imgtmp = hardcopy(h,'-dzbuffer','-r0');
imwrite(imgtmp,hot,'picname.png');

Naturally, 'picname.png' and picdata are changing each time around.

Is there a better way to invisibly plot and save these pictures? The processing time mostly takes place inside imwrite, with hardcopy coming second. The whole purpose of the pictures is just to get a general idea of what the data looks like; I'm not going to need to load them back into Matlab to do future processing of any sort.

A Blue Shoe
  • 157
  • 2
  • 11
  • Below [this question](http://stackoverflow.com/questions/24803383/save-high-resolution-figures-with-parfor-in-matlab#comment38498896_24803383) was a discussion about your problem. The question itself+answer is probably useful as well! – Robert Seifert Aug 08 '14 at 22:15
  • Hmm, those are definitely good suggestions, but won't work for me. I can't suppress _all_ my figures since there are a couple that are supposed to pop up at the end, I'm not on a UNIX platform, and I do not have the Parallel Computing Toolbox so I can't use `parfor`. – A Blue Shoe Aug 08 '14 at 22:47
  • Pipe the data to a separate Java program. – Yvon Aug 09 '14 at 00:49
  • Have you tried writing the image as an indexed image (picdata + a colormap) directly rather than via hardcopy? – nkjt Aug 09 '14 at 12:56
  • How would I do that? I could give it a try. – A Blue Shoe Aug 11 '14 at 15:11

1 Answers1

1

Try to place the figure off-screen (e.g., Position=[-1000,-1000,500,500]). This will make it "Visible" and yet no actual rendering will need to take place, which should make things faster.

Also, try to reuse the same figure for all images - no need to recreate the figure and image axes and colormap every time.

Finally, try using my ScreenCapture utility rather than hardcopy+imwrite. It uses a different method for taking a "screenshot" which may possibly be faster.

Yair Altman
  • 5,704
  • 31
  • 34