Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Creating Figure Montages - Possible Without Saving Individual Files? Possible Using Illustrator (.ai) Format?

Subject: Creating Figure Montages - Possible Without Saving Individual Files? Possible Using Illustrator (.ai) Format?

From: David Painter

Date: 11 May, 2012 06:20:22

Message: 1 of 2

Hi All,

I'm creating montages of image files using the imwrite function. I'm wondering if I can speed this process by not saving figures to disk? Also, I'd love if these montages were editable in Adobe Illustrator. In other words, I'd love if the montages were in .ai format. Is this possible?

Here's an example that creates a "vertical" montage of 5 plots of random data in .png format.

%%
num_plots = 5;
montage = [];
format = 'png'; % crashes if set to 'ai'; variable requires just file extension without the '.'

for P = 1:num_plots
    
    close('all')
    h = figure;
    
    tit = [ 'Plot Number ' num2str(P) '.' format ];
    plot( randperm(10) )
    title(tit)
    
    saveas(h, tit)
    
    montage = cat(1, montage, imread(tit) );
    
end

imwrite(montage, 'montage.png', format)
imwrite(montage, 'montage.ai', 'ai')
%%
    
So, there are two issues... Can I replace the saveas command with a function that does not write to disk? Second, can I replace imread and imwrite with functions that support .ai? Obviously, the program crashes on the last line as imwrite does not support .ai format. Also, the program crashes if the variable format = 'ai', as imread does not support ai.

Any ideas?

David

Subject: Creating Figure Montages - Possible Without Saving Individual Files? Possible Using Illustrator (.ai) Format?

From: David Painter

Date: 2 Jul, 2012 10:06:07

Message: 2 of 2

Still no help? =)

Today, I stumbled on part of the answer - a way to create plot montages without saving plots to disk. The getframe function can be used to retrieve the pixels that comprise the figure, but the figure needs to displayed, slowing down montage creation. In other words, the command figure('visible', 'off') is overridden by getframe. I knew something like this would be possible, but the main question is whether the same idea can be applied to vectorised figures - can montages of vectorised figures be created using Matlab?

Here's the code using getframe to avoid saving individual figures to disk:

num_plots = 5;
montage = [];
format = 'png';

for P = 1:num_plots
    
    close('all')
    h = figure('visible', 'off');
    
    tit = [ 'Plot Number ' num2str(P) '.' format ];
    plot( randperm(10) )
    title(tit)
    
    im = getframe(h);
    
    montage = cat(1, montage, im.cdata );
    
end

imwrite(montage, 'montage.png', format)



"David Painter" <david.ross.painter@gmail.com> wrote in message <joib36$q6l$1@newscl01ah.mathworks.com>...
> Hi All,
>
> I'm creating montages of image files using the imwrite function. I'm wondering if I can speed this process by not saving figures to disk? Also, I'd love if these montages were editable in Adobe Illustrator. In other words, I'd love if the montages were in .ai format. Is this possible?
>
> Here's an example that creates a "vertical" montage of 5 plots of random data in .png format.
>
> %%
> num_plots = 5;
> montage = [];
> format = 'png'; % crashes if set to 'ai'; variable requires just file extension without the '.'
>
> for P = 1:num_plots
>
> close('all')
> h = figure;
>
> tit = [ 'Plot Number ' num2str(P) '.' format ];
> plot( randperm(10) )
> title(tit)
>
> saveas(h, tit)
>
> montage = cat(1, montage, imread(tit) );
>
> end
>
> imwrite(montage, 'montage.png', format)
> imwrite(montage, 'montage.ai', 'ai')
> %%
>
> So, there are two issues... Can I replace the saveas command with a function that does not write to disk? Second, can I replace imread and imwrite with functions that support .ai? Obviously, the program crashes on the last line as imwrite does not support .ai format. Also, the program crashes if the variable format = 'ai', as imread does not support ai.
>
> Any ideas?
>
> David

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us