matlab图像处理

一、彩色图像变灰色

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);


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值