0

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

  • imgRGB is 15x15x3. Doing signal=cat(2,signal,imgRGB); increases signal to 15x30x3, ..., 15x15Nx3, which does not seem to be a good way in storing many pictures.

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?

Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697

1 Answers1

4

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.

Daniel
  • 36,610
  • 3
  • 36
  • 69
  • 1
    @Masi You coudl write your own video encoder based on vector graphics. This would take, approximately between 2 and 5 years. Also, you could instead of saving a video, save frame per frame vactor grpahics objects. However, the main reason this is not done is because i'd take enormous amount of memory – Ander Biguri Mar 14 '16 at 17:26
  • 4
    @Masi you have MB of eps files per 15x30 images? And that is not enormous amount of memory? A typical video would contain 24fps, meaning that if you use 1MB files, 41 seconds of video would take 1Gb. And thats for a image 15x30, about the size of a couple of characters in your screen! I might have misunderstood, and each eps is 100Kb, but that means that 1Gb of video is about 6 minutes..... – Ander Biguri Mar 14 '16 at 17:29
  • @AnderBiguri I have 1 MB (= 100kB*10) i.e. for all 10 .eps files of 10 seconds for 100 second video. One .eps file is 15x15. I cannot get the same result as you as a Gb. How did you do it? I need to study this more. – Léo Léopold Hertz 준영 Mar 14 '16 at 17:34
  • @Masi Are you going to write a file **per second** ? I did the maths using 24fps. – Ander Biguri Mar 14 '16 at 17:35
  • 1
    @Masi What do you mean *Just update them when needed*? This is a video, rigth? Why would you have a video going so slow? However, even if there is a remote scenario where you want a video with a single frame per second, you do understand this is a very rare thing, and no one would create a video codec for this! Thus, videos are created to store maximum amount of information with lss amount of memory. Realise, that an uncompresed, **raster** video of the typical Hollywood movie is about 1Tb of memory. Vector graphics generally are more memory demanding than raster. – Ander Biguri Mar 14 '16 at 17:39
  • 1
    @Masi: I inserted a practical workaround at the end of my answer. Wrapping all in HTML/JS you won't end up with a video, but with something that behaves like a video. – Daniel Mar 14 '16 at 17:46
  • 1
    @AnderBiguri I disagree with you. The "simple" vector graphics, like graphs, are very small in vector graphics but same graphics in bitmap is almost the same size as photography of the same resolution and colour depth. But photo-like images in vector format are bigger than bitmaps. We must take in account that any vector graphics must go through raster image processor to be displayed and/or printed. – Crowley Mar 14 '16 at 18:02
  • @Crowley They are smaller when there is little to draw, indeed! But as Masi says, 100Kb for a 15x30 iamge. Thats not small. Also, he is getting this images from the raster of MATLAB figure, thus they will be big independent of the data. – Ander Biguri Mar 14 '16 at 18:03
  • 1
    @Masi because you can image it as "a red circle of diameter D shall be at position of **r**" but screen and printer work with bitmaps only that are "pixel `[ii,jj]` will have red colour". The advantages of vector graphics are size proportional to the graphics content and that rasterisation is happening at very end of the (printing) process. Disadvantages are the same :) – Crowley Mar 14 '16 at 18:08
  • 1
    @AnderBiguri If you generally use vector format to work with photo-like graphics you get, generally, bigger files... There must be decision what is more suitable for the application - bitmap or vector. Both have their pros and cons. – Crowley Mar 14 '16 at 18:11
  • @Crowley Can you please explain this topic more thoroughly in your answer. It is interesting. I have a case that I need to actually loop two axes at the same time and show their effect in video of picture `signal(1:1 + windowWidth,1:1 + windowWidth,:)`. Matlab does not seem to do it correctly. – Léo Léopold Hertz 준영 Mar 14 '16 at 18:12
  • 2
    @Masi This doesn't worth an answer since I'm talking about (stationary) graphics and you are interested in video and much more information than I can provide can be read, for example, there: http://graphicdesign.stackexchange.com/questions/41/what-web-graphics-formats-to-use/253#253 – Crowley Mar 14 '16 at 18:29