MATLAB将图片输出视频及GIF文件

将图片输出为视频及GIF

clear;clc
Path = 'I:Path\';
Folder = 'Foldername\';
Data = imageDatastore([Path,Folder]);
V = VideoWriter([Path,Folder,'Movie.avi']); % 输出AVI文件名字
V.FrameRate = 50; % 帧率,40fps
V.Quality = 90;   % 质量,百分比,90%
GIF = [Path,Folder,'GIF.gif'];
open(V);
for bnumber = 1:length(Data.Files)
    set(0,'DefaultFigureVisible', 'off');
    img = readimage(Data,bnumber);
    writeVideo(V, img); %%% 输出视频文件
    % 输出GIF文件
    imshow(img(1:5:end,1:5:end));
    CurrFrame = getframe;   % 获取像素,否则无法显示动画
    im = frame2im(CurrFrame);  
    [A,map] = rgb2ind(im,256);  %RGB图像转换为索引图像
	if bnumber == 1
		imwrite(A,map,GIF,'gif','LoopCount',Inf,'DelayTime',0.005);  % DelayTime表示写入的时间间隔
	else
		imwrite(A,map,GIF,'gif','WriteMode','append','DelayTime',0.005);
    end
    close
end
close(V); %%% 关闭视频输出

你可能感兴趣的:(PIV实验相关,文件读取)