anyway to save figure as uint8 format

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 Commenti

Suggested optimization: writevideo() the content as it is generated, instead of writing it to disk.
the jpg generated are using parallel loop. which is not supported by writevideo.
In that case I would suggest using fopen()/fwrite()/fclose()
I'm not sure if I get you point, do you mean to use fopen to open the figure?
Yu Li, did you even see my answer below? If it doesn't do what you want, put a comment below it stating why it's not working for you.
filename = sprintf('%05d.bin', frame_number);
fid = fopen(filename, 'w'); %not 'wt' !!
fwrite(fid, YourArrayOfPixelData, '*uint8');
fclose(fid);
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?

Accedi per commentare.

Risposte (1)

Image Analyst
Image Analyst il 26 Ago 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 Commenti

Thanks for your demo, but looks it does not solve this specific problem. The objective of this question is to save figure as unit8 file.
here is how I generate the .jpg files:
f=figure('visible','off');
some operations...
print(fig_name,'-djpeg','-r400');
after all these finished, I'll make an animation regarding depends on if I really need it.
the weakness of animation making is that, the video object must be write with time sequential, i.e. the writeVideo function can not be conducted under parallel condition. if I have 10000 figures, I have to write 10000 times, which may be very long.
meanwhile, using the gca to get the current frame, may lead the resolution very low, I have not find any other method to get the high resolution image parameter except read the figure back.
do you have some suggestions?
Thanks! Yu
Sometimes the best thing to do is to create into a matrix directly instead of displaying on screen and then rendering. But whether you can do so effectively depends a lot on what graphics you are constructing.
Yu, again, you don't need to create/save the figures onto disk just to read them back in again to create a movie. You can just keep the array in memory and use that without creating a file on disk.
Hi:
if I could keep the array in memory and save it as frame at the end of calculation, the problem should be able to be solved. do you have any suggestions about this?
Thanks!
Yu
What kind of plotting are you doing?
contour plot
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)

Accedi per commentare.

Categorie

Richiesto:

il 25 Ago 2018

Commentato:

il 27 Ago 2018

Community Treasure Hunt

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

Start Hunting!

Translated by