MATLAB Answers

Translated by

이 페이지의 내용은 영어에서 자동 번역되었습니다. 자동 번역 기능을 해제하려면 "<a class="turn_off_mt" href="#">여기</a>"를 클릭하십시오.

0

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

Asked by hana razak on 25 Jul 2018
Latest activity Commented on by hana razak on 7 Aug 2018
Accepted Answer by Jan
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

  0 Comments

Sign in to comment.

1 Answers

Answer by Jan
on 25 Jul 2018
 Accepted Answer

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 Comments

Hello Mr. Jan,
It's been over a week since your last response. I hope you are well and healthy so you can come back to help us here as usual.
I sincerely pray for your health because this is not your usual response.
I really need the last answer so I can process my video way much faster instead of doing it one by one.
If Mr. Jan is not available, I hope someone else can help me with this. I'm waiting for my question to be answered as soon as possible.
Thank you so much.
@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:
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.

Sign in to comment.



Translated by