How to have Vector Graphics Video in Matlab?

I would like to have a vector graphics video output such that I can resize the window during the video play in Matlab 2016a. I would like to have similar characteristics as .eps 3 format in pictures but for video. Some overview of the pseudocode

  1. read picture data as .mat in 10 second chunks so you can choose any vector picture format which probably works in video
  2. have figure handles in colormap(gray) instead of storing pictures first to imgRGB/imgPNG/... with specific customizations
  3. add figure handles hFig to the list signal
  4. loop figure handles for video

where I am uncertain about having many figure handles in a list and looping them inside a major figure. It may not be possible.

My current approach with non-vectorised imgRGB/imgPNG/... which I would like to reject because of several problems with resizing window and zooming

Pseudocode

%% Make vector graphics pictures that are parts of the video
signal=[];
for k=1:3
    A=load(filenameMat); % = A.time, A.potential, A.matrix
    % TODO convert to some vector form each picture which should work in video too

    % I can make N .eps pictures and figure handle to all of them. 
    % So probably having a list of those figure handles is the way to go. 
    hFig=figure(); % but not sure if possible with vectorised video play

    signal=cat(2,signal,hFig); % pseudo
end

%% Put parts together in the main Figure i.e. video
% http://stackoverflow.com/a/29952648/54964
windowWidth = 320;
hFig=figure('Menubar','figure', 'NumberTitle','off', 'Color','k', 'Visible', 'on');
hImg = imshow(signal(:,1:1 + windowWidth,:), ...
    'InitialMagnification', 100, 'Border', 'tight');

vid = VideoWriter('signal.avi');
vid.Quality = 100;
vid.FrameRate = 60;
open(vid);

M = size(signal,2);
for k=1:(M - windowWidth)
    set(hImg, 'CData', signal(:,k:k + windowWidth,:))
    writeVideo(vid, getframe());
end

close(vid);

How can you have vector graphics video output in Matlab?

Upvotes: 0

Views: 322

Answers (1)

Daniel
Daniel

Reputation: 36710

It is not possible to put vector graphics into a video. Any video format supported by MATLAB (and any video format I know) is based on raster graphics. When writing a video you have to accept that it is rastered.

There is another thing with your code, I don't understand. You already start with a rastered image (signal(:,1:1 + windowWidth,:)). The best possible quality you can achieve is writing the video in exactly that resolution, not adding any additional rasterisation. Use writeVideo(vid, signal(:,k:k + windowWidth,:)); for this special case.

Typically the best way to share a "video" based on vector graphics is to share runnable code which generates the graphics. This is for example what Adobe Flash, Microsoft Silverlight and similar do. You could choose the same way and share your code generating the graphics either as blank source code (requires MATLAB to run) or as a JAR (requires you to have the Compiler SDK, expensive!).

To have a cheap and very accessible way to share your 10 second video of 10 vector graphics, I would use some HTML/JS to wrap them into an animation. You will end up with 12 loose files, but all standard technology which can be viewed on most systems.

Upvotes: 4

Related Questions