anyway to save figure as uint8 format
6 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2018-8-26
filename = sprintf('%05d.bin', frame_number);
fid = fopen(filename, 'w'); %not 'wt' !!
fwrite(fid, YourArrayOfPixelData, '*uint8');
fclose(fid);
Image Analyst
2018-8-26
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?
回答(1 个)
Image Analyst
2018-8-26
See my attached demo where I plot a surface in a graph, then make a movie out of that surface as it changes.
7 个评论
Walter Roberson
2018-8-27
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)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!