How to get individual image from video file with the .mat format?

3 visualizaciones (últimos 30 días)
Hello,
I have video files of the color image (480x640x3 uint 8) and depth image (480x640 uint 16) with the .mat format both. I need to extract frames and save individual frames to separate image of jpeg files.
I tried a few ways to extract those files as suggested but they just didn't work such cell2mat and cat. I failed to convert using VideoReader since the .mat is not supported.
Am I need to convert the files to .mp4 video format first? If yes, how to do it? Any tips?
Thank you very much

Respuesta aceptada

Jan
Jan el 25 de Jul. de 2018
MAT files are created by Matlab and can contain data of any class and shape. Knowing the class of the single images is not sufficient to know, how the movie is store inside the file. The readers cannot guess this detail, but you can check it easily:
Data = load('YourFile.mat')
disp(Data)
What do you see? After a load command, we are not talking about importing from a MAT file, but now the inputs are the variables found in this files. And if you post, what this is, we can create a solution.
Usually It is useful if you post the failing code and the corresponding error messages.
  10 comentarios
Stephen23
Stephen23 el 7 de Ag. de 2018
Editada: Stephen23 el 7 de Ag. de 2018
@hana razak: Jan made one trivial mistake with the indexing, which is easy to fix:
Data = load('YourFile.mat');
nFrame = numel(Data.imagecolor);
for kk = 1:nFrame
imwrite(Data.imagecolor{kk}, ...
fullfile(Folder, sprintf('%06d.jpg',kk)));
end
"I really need the last answer so I can process my video way much faster instead of doing it one by one."
Given that your goal is to save the frames individually, I doubt that there is any convenient way to speed up this process: the slowest part is going to be the file reading/writing, not the very simple loop that occurs in MATLAB. Any attempt to speed up your code should be focused on the hard-drive (e.g. use an SSD rather than a HD, or a combo drive). Rather than guessing how to speed up this process you need to learn where the bottle-necks are. Start by using the profiler:
hana razak
hana razak el 7 de Ag. de 2018
Thank you so much.
It's work well for Data.imagecolor but it doesn't work for Data.imagedepth.
When I run for Data.imagedepth, it gives this error messages.
Error using writejpg>set_jpeg_props (line 183)
UINT16 image data requires bitdepth specifically set to either 12 or 16.
Error in writejpg (line 49)
props = set_jpeg_props(data,varargin{:});
Error in imwrite (line 472)
feval(fmt_s.write, data, map, filename, paramPairs{:});
Error in test_squat (line 13)
imwrite(Data.imagedepth{kk}, ...
I hope you can help me in solving this error.
Thank you so much.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Import and Analysis en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by