anyway to save figure as uint8 format

6 views (last 30 days)
Yu Li
Yu Li on 25 Aug 2018
Commented: Walter Roberson on 27 Aug 2018
Hi: I want to make an animation with lots of figures. what I did is:
(1)write a for-loop to generate the .jpg file. (2) use writevideo to generate the animation based on the .jpg file.
the problem is that, if the number of .jpg files a huge, it cost lots of time to continuously read the .jpg file using function 'imread'
since the imread is to read the .jpg file into unit8 format, so I want know if there is anyway to save the figures as unit8 format, if I could save them into one structure file, I only have to read one time. it should make the animation created faster.
Thanks! Yu
  7 Comments
Walter Roberson
Walter Roberson on 26 Aug 2018
filename = sprintf('%05d.bin', frame_number);
fid = fopen(filename, 'w'); %not 'wt' !!
fwrite(fid, YourArrayOfPixelData, '*uint8');
fclose(fid);
Image Analyst
Image Analyst on 26 Aug 2018
Yu Li, you can make the video without the intermediate steps of creating a JPG file and then reading it back in you know. If you don't know how, then ask. Also, what format did you use to write the JPG files if it wasn't uint8? Also why are you using JPG as the format for the intermediate files rather than lossless PNG format?

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 26 Aug 2018
See my attached demo where I plot a surface in a graph, then make a movie out of that surface as it changes.
  7 Comments
Walter Roberson
Walter Roberson on 27 Aug 2018
It takes a little work to render a contour plot to memory, but it is doable. If you use the syntax
[C,h] = contour(...) returns the contour matrix C containing the data that defines the contour lines, and the Contour object h.
and then you delete the contour object, then you would be left with C, the contour matrix. The contour matrix contains structured data that is a little bit of a nuisance to work with. Fortunately, Duane created https://www.mathworks.com/matlabcentral/fileexchange/38863-extract-contour-data-from-contour-matrix-c which extracts the data as line segments by coordinates.
With the line segments as coordinates in hand, you can use Vision System Toolbox insertShape to draw the lines into a matrix, and insertText() to add any labels you want. You can do this at arbitrary resolution.
You can then store the matrix in a 4D array indexed by the parfor loop index (row, col, color, frame number)

Sign in to comment.

Categories

Find more on Animation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!