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

조회 수: 3 (최근 30일)
hana razak
hana razak 2018년 7월 25일
댓글: hana razak 2018년 8월 7일
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

채택된 답변

Jan
Jan 2018년 7월 25일
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
Stephen23
Stephen23 2018년 8월 7일
편집: Stephen23 2018년 8월 7일
@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 2018년 8월 7일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by