MATLAB Answers

Convert AVI file to series of images

조회 수: 260(최근 30일)
NS 10 Mar 2012
댓글: Image Analyst 5 Mar 2020
Hi all,
I have a AVI file that was formatted in MATLAB. I wish to convert it to a series of tif images. I am not able to do this in imageJ. Is it possible?

  댓글 수: 0

Sign in to comment.

채택된 답변

Chandra Kurniawan
Chandra Kurniawan 11 Mar 2012
This is the simpler version :
obj = mmreader('rhinos.avi');
vid = read(obj);
frames = obj.NumberOfFrames;
for x = 1 : frames
You can use your own video by replacing 'rhinos.avi' with your own.
I hope this works!

  댓글 수: 4

표시 이전 댓글 수: 1
SBunny 14 Jun 2013
Thank you so much
Farhan Ferdous
Farhan Ferdous 6 Jul 2017
which directory will I get the images?
Image Analyst
Image Analyst 6 Jul 2017
He did not specify a folder, unfortunately, so the images will go into the current folder, the same one as the m-file.

Sign in to comment.

추가 답변(2개)

Image Analyst
Image Analyst 11 Mar 2012
Here are the key lines:
outputFolder = 'c:/users/whatever'; % Change this!
% Read in the movie.
mov = aviread(movieFullFileName);
% Determine how many frames there are.
numberOfFrames = size(mov, 2);
for frame = 1 : numberOfFrames
% Extract the frame from the movie structure.
thisFrame = mov(frame).cdata;
% Create a filename.
outputBaseFileName = sprintf('Frame %4.4d.png', frame);
outputFullFileName = fullfile(outputFolder, outputBaseFileName);
% Write it out to disk.
imwrite(thisFrame, outputFullFileName, 'png');

  댓글 수: 14

표시 이전 댓글 수: 11
Guillaume 29 Mar 2018
In matlab, the default TIFF compression mode (for RGB images) is 'packbits', so TIFF are compressed by default. packbit is a run-length encoding compression method. It is completely lossless. You can override the compression mode, the only lossy TIFF mode supported by imwrite is 'jpeg'.
PNG is always lossless and in my opinion a better format than TIFF.
Gaia Gbola
Gaia Gbola 5 Mar 2020
Hello, I am using the DEMO imaging version for MATLAB, but your code seems not to run on it, it does not recognize the function aviread. Is it possible that is because of the version that I have?
Image Analyst
Image Analyst 5 Mar 2020
aviread() is a really old function and it may have been removed by now. You'll need to replace it with VideoReader. See attached demos for help and examples.

Sign in to comment.

Sushil  Sharma
Sushil Sharma 23 Sep 2019
편집: Sushil Sharma 23 Sep 2019
Upadte answer
In the lestest veriosn of matlab, we have to use VideoReader instead of mmreader,then you are able to convert any video file into a frames
Here the simple of code to get the frames
%% Change .avi format to images frames
obj = VideoReader('test2.avi');
vid = read(obj);
frames = obj.NumberOfFrames;
for x = 1 : frames

  댓글 수: 0

Sign in to comment.


Translated by