一、彩色图像变灰色
num_frame = 500;
for n = 1:num_frame
frame_name = strcat('0', num2str(n), '.jpg');
I = imread(frame_name);
I = rgb2gray(I);
I = imresize(I, [320, 240]);
imwrite(I, strcat('00', num2str(n), '.jpg'));
end
二、图片转换为avi视频
% Get a directory listing.
filePattern = fullfile('*.jpg');
pngFiles_old = dir(filePattern);
% Open the video writer object.
[~,idx]= sort([pngFiles_old(:).datenum]);
pngFiles = pngFiles_old(idx(:));
writerObj = VideoWriter(fullfile(['out','.avi']));
writerObj.FrameRate = 10; %帧率
writeObj.profil='Indexed AVI';
% Go through image by image writing it out to the AVI file.
open(writerObj);
for frameNumber = 1 : length(pngFiles)
% Construct the full filename.
baseFileName = pngFiles(frameNumber).name;
fullFileName = fullfile(baseFileName);
% Display image name in the command window.
fprintf(1, 'Now reading %s\n', fullFileName);
% Display image in an axes control.
imageArray = imread(fullFileName);
imshow(imageArray,[0 25]); % Display image
drawnow; % Force display to update immediately.
% Write this frame out to the AVI file.
% writeVideo(writerObj, thisimage);
writeVideo(writerObj,imageArray);
end
% Close down the video writer object to finish the file.
close(writerObj);