VideoReader - cropped frame

12 次查看(过去 30 天)
Hello,
I'm using VideoReader to import *.avi file to Matlab.
My original file is quite large, it's 480x480 pixels, 24 bits per pixel.
If I'm trying to read all the frames using getFrame as in the code below, it takes a lot of time.
k = 1;
while hasFrame(xyloObj)
mov(k).cdata = readFrame(xyloObj);
k = k+1;
end
So I get a struct, mov, with frames size of 480x480x3.
My questions are: A) how can read only 8 bits per pixel, so my struct would be only "one layer"... 480x480x1? B) how can I read only a cropped region every frame? I mean can I read 64x64 ROI every loop, instead of read the full frame every time?
Thank You!

采纳的回答

Walter Roberson
Walter Roberson 2015-10-6
If your image is RGB24 then VideoReader always reads and outputs the entire data. If your image was indexed then you could specify 'native' to get back a struct that had the indexing information and the colormap and so would be slightly faster.
VideoReader always returns the entire frame; there is no crop option (at least up to R2015b).
The methods of setting cropping and format to return data only work for live video, not reading from a file.
  3 个评论
Michal Semonsky
Michal Semonsky 2020-6-8
Hello, is this information still up too date or is there any crop function within video reader? Thank you
Walter Roberson
Walter Roberson 2020-6-8
The information is still up to date: there is no crop function within VideoReader, or vision.VideoFileReader
What is different since that time is that there is now an imcrop3 that can be (carefully) applied to a Rows x Columns x Panes x Images 4D array to reduce the numeber of rows and columns on every image, which could be useful in cropping if you used the read() method to read multiple frames.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by