MATLAB视频处理

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

MATLAB AVI视频资源处理方案

1、用matlab读取avi电影(只能读一定压缩各式的avi电影)

aviinfo('d:\j.avi');%显示存在d盘的电影j.avi的信息,在matlab2010版本中,该函数换成mmreader

mov=aviread('d:\j.avi');%读入存在d盘的电影j.avi

movie(mov);%放映电影

2、将电影转成图片序列

mov=aviread('d:\j.avi');%读入

fnum=size(mov,2); %读取电影的祯数,mov为1*temp

for i=1:fnum

strtemp=strcat('d:\转换的图片\',int2str(i),'.','jpg'); %将每祯转成jpg的图片

imwrite(mov(i).cdata(:,:,Smile,mov(i).colormap,strtemp);

end

3、aviread有两种使用方式:

aviread(filename);

aviread(filename, index);%读取avi文件的第index帧图像;

例:

mov = aviread('highwayI_raw.A VI')

mov = aviread('highwayI_raw.A VI',1) %读取第一帧图像

4、读取图像以后储存的格式是一个结构体,该结构体有两个元素:cdata和colormap

例:

frame = aviread('highwayI_raw.A VI', i);

frame.cdata 表示了一个数据数组,彩色图像就是3维的,灰度图像就是2维的。

1

frame.colormap 见(help aviread)

5、将彩色图像转换为灰度图像,很简单:

frame = aviread('highwayI_raw.A VI', i);

f_gray = rgb2gray(frame.cdata); 这样就可以将文件的第i帧转换为灰度图像。

6、 imwrite的用法:

imwrite(recover_image, 'recover.jpg', 'jpg');

在matlab2010中,上述的函数都发生了变化:

读取函数为mmreader,该函数可以读取所有的多媒体文件,返回值为一个结构体;然后可以用read函数进行读取文件,用法如下例:readobj = mmreader('Laboratory_raw.avi');

vidframe = read(readobj);

mov.cdata = vidframe(:,:,:,1);

mov.colormap = [];

movie(mov);

7、doc aviread from MATLAB

aviread

Read Audio/Video Interleaved (AVI) file

Note aviread will be removed in a future release. Use VideoReader instead.

Syntax

2

mov = aviread(filename)

mov = aviread(filename, index)

Description

mov = aviread(filename) reads the AVI movie filename into the MATLAB movie structure mov. If filename does not include an extension, then .avi is used. Use the movie function to view the movie mov. On UNIX platforms, filename must be an uncompressed AVI file.

mov has two fields, cdata and colormap. The content of these fields varies depending on the type of image.

Image Type cdata Field colormap Field

Truecolor Height-by-width-by-3 array of uint8 values Empty

Indexed Height-by-width array of uint8 values m-by-3 array of double values

aviread supports 8-bit frames, for indexed and grayscale images, 16-bit grayscale images, or 24-bit truecolor images.

Note, however, that movie only accepts 8-bit image frames; it does not accept 16-bit grayscale image frames.

mov = aviread(filename, index) reads only the frames specified by index. index can be a single index or an array of indices into the video stream. In AVI files, the first frame has the index value 1, the second frame has the index value 2, and so on.

8、doc aviinfo from MATLAB

avifile

3

相关文档
最新文档