splitting a video into frames using image function after using mmreader to read video file...

*I wasn't being able to bring an avi file into the workspace, so I brought the video into the MATLAB file and played it using implay...then I want to split it into its individual frames..
According to the solution by Walter Roberson on
n=size('cell.avi')
n =
1 8
for frame= 1:n
('cell.avi')(frame)=getframe;
|
But I get_ :Error: Unbalanced or unexpected parenthesis or bracket.
_
image function!!*
Now I want the individual frames as individual images, so I put: image(('cell.avi')(1).cdata) image(('cell.avi')(1).cdata) | *Error: Unbalanced or unexpected parenthesis or bracket. * *What is wrong? I've been able to load the movie, but now I can't split it into the frames using

2 件のコメント

Walter Roberson
Walter Roberson 2011 年 10 月 17 日
I never wrote that code!
Yagnaseni Roy
Yagnaseni Roy 2011 年 10 月 17 日
I meant mage(fractogene(117).cdata)...you suggested this

サインインしてコメントする。

 採用された回答

Image Analyst
Image Analyst 2011 年 10 月 18 日
Look at the help for mmreader() . . . again . . . more carefully this time. You'll see read() does not take a string, it take the movie object, and the number of the frame you want to read. So instead of
video = read('cell.avi');
you'd want
% Read from ii from movie M
oneFrame = read(M, ii);

7 件のコメント

Yagnaseni Roy
Yagnaseni Roy 2011 年 10 月 18 日
But in order to define movie M, I'd need
M= aviread('cell.avi') first, but aviread does not work, as said in my post.
Yagnaseni Roy
Yagnaseni Roy 2011 年 10 月 18 日
HEY IT WORKED!!
This is the code I used:
M=mmreader('cell.avi');
for ii = 1:length(M)
oneFrame = read(M, ii);
end
>> imshow(oneFrame)
Yagnaseni Roy
Yagnaseni Roy 2011 年 10 月 18 日
HOWEVER, BEFORE I FINISH OFF AND ACCEPT THIS ANSWER, PLEASE TELL ME WHAT I SHOULD ADD IN THIS CODE TO ALLOW ME TO SEE ALL OF THE FRAME, SINCE CURRENTLY, IT JUST SHOWS THE 1ST FRAME...
Walter Roberson
Walter Roberson 2011 年 10 月 18 日
M = mmreader('cell.avi');
N = M.NumberOfFrames;
for ii = 1:N
image(M.read(ii));
pause(0.1);
end
Or perhaps you want
M = mmreader('cell.avi');
N = M.NumberOfFrames;
for ii = 1:N
Frames{i} = M.read(ii));
end
Frames = cat(4,Frames{:});
implay(Frames);
Yagnaseni Roy
Yagnaseni Roy 2011 年 10 月 18 日
THANKS!! THIS REALLY HELPED!
Yagnaseni Roy
Yagnaseni Roy 2011 年 10 月 19 日
Btw,
referring to M = mmreader('cell.avi');
N = M.NumberOfFrames;
for ii = 1:N
image(M.read(ii));
pause(0.1);
end
HOW WOULD I CALL FOR AN INDIVIDUAL FRAME...SUPPOSE FRAME 5?? i TRIED image(M.read(5));
...IS THIS NOT SUPPOSED TO WORK?
Yagnaseni Roy
Yagnaseni Roy 2011 年 10 月 19 日
Doing this, I seem to get the last frame each time...even when I change to image(M.read(6));image(M.read(20));....they all look the same.

サインインしてコメントする。

その他の回答 (2 件)

Sean de Wolski
Sean de Wolski 2011 年 10 月 17 日
n=size('cell.avi')
will say that n = [1 8] since 'cell.avi' is an eight letter long string (row vector of characters).
Here's probably closer to what you want:
M = aviread('rhinos.avi');
for ii = 1:length(M)
image(M(ii).cdata)
pause(.1)
end

10 件のコメント

Yagnaseni Roy
Yagnaseni Roy 2011 年 10 月 17 日
aviread doesn't work on my video...so I used mmreader...
HERE'S WHAT I GOT:
M=mmreader('cell.avi')
Summary of Multimedia Reader Object for 'cell.avi'.
Video Parameters: 29.97 frames per second, RGB24 336x96.
480 total video frames available.
>> for ii= 1:length(M)
image(M(ii).cdata)
pause(.1)
end
No appropriate method, property, or field cdata for class
mmreader.
Yagnaseni Roy
Yagnaseni Roy 2011 年 10 月 17 日
Also, note that it says:
length(M)
ans =
1
WHICH IS UNREASONABLE!!
Sean de Wolski
Sean de Wolski 2011 年 10 月 17 日
No. mmreader is its own class that is defined in that size.
>> M.NumberOfFrames
will tell you what you're looking for.
Yagnaseni Roy
Yagnaseni Roy 2011 年 10 月 17 日
I tried what SEAN DE said...this is what I got..
M=NumberOfFrames('cell.avi')
Undefined function 'NumberOfFrames' for input arguments of type
'char'.
>> M.NumberOfFrames
Undefined variable "M" or function "M.NumberOfFrames".
PLEASE GIVE A CODE I COULD TRY!!
Walter Roberson
Walter Roberson 2011 年 10 月 17 日
M = aviread('cell.avi');
N = M.NumberOfFrames;
for ii = 1:N
image(M.read(ii));
pause(0.1);
end
For more information see
http://www.mathworks.com/help/techdoc/ref/videoreader.read.html
Yagnaseni Roy
Yagnaseni Roy 2011 年 10 月 17 日
As I said earlier, Aviread does not work on this video it keeps saying
Error using aviread (line 81)
Unable to locate decompressor to decompress video stream
Yagnaseni Roy
Yagnaseni Roy 2011 年 10 月 17 日
I ALSO TRIED:
video = read('cell.avi')
Undefined function 'read' for input arguments of type 'char'.
Yagnaseni Roy
Yagnaseni Roy 2011 年 10 月 17 日
USING movie('cell.avi') opens imtool, but the screen is blank..
I also tried movie('cell.avi',1), hoping that would give me the first frame of the video, but again, imtool opened a blank screen.
Yagnaseni Roy
Yagnaseni Roy 2011 年 10 月 17 日
Apparently, 'cell.avi' is a 8 character string and none of the functions are working on it..
Walter Roberson
Walter Roberson 2011 年 10 月 18 日
M = mmreader('cell.avi');
N = M.NumberOfFrames;
for ii = 1:N
image(M.read(ii));
pause(0.1);
end

サインインしてコメントする。

Dimple Chawla
Dimple Chawla 2012 年 4 月 17 日

0 投票

hey, it really helped me too, actually i'm working on similar project like calculating difference of object property in frame such as 1st and the 20th or the last frame. Can u help on this.?? I will deftly appreciate your effort. Thanks reply asap

カテゴリ

ヘルプ センター および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by