This paper introduces the method of reading and writing pictures, reading image sequence and read AVI video using matlab:
First, read and write images
Use MATLAB to read an image and save
1 % Filename:imagereadwrite2CLC; 3 Clear; 4 i = imread ('d:\\aa3.bmp');% Open d:\\aa3.bmp image 5 imshow (i ); % Display image 6'd:\\aa4.jpg');% save Image as D:\\aa4.jpg
The use of Matlab reading and writing can also be used for image format conversion, JPG images converted to 256-color grayscale Image:
1 % filename:rgbtograyimage2 i = imread ('d:\\1.jpg'); Read RGB image 3 j = Rgb2gray (i); %RGB image to grayscale image 4imshow (j); 5 ' d:\\1.bmp ') % Save time Select BMP format
Second, read the image sequence
Use MATLAB to read the sequence of images and display
1%filename:imagesequence2 CLC3 Clear4Dlist=dir ('d:\\imagesequence\\*. JPG'); 5N=length (dlist); %Number of Images6 forI=1: N7Image_data{i}=imread (['d:\\imagesequence\\', Dlist (i). name]); 8 imshow (Image_data{i});9Pause0.0);Ten Drawnow; OneEnd
Third, read the AVI format video
1%Filename:videoread2 CLC;3 Clear;4Video = Mmreader ('D:\\videotest.avi');5Nframes = video. Numberofframes; %get the number of frames6H = video. Height; %Get High7W = video. Width; %Get width8Rate =video. framerate;9%preallocate movie structure.Tenmov1: nframes) =struct('CDATA', Zeros (H,w,3,'uint8'),'ColorMap',[]); One%read one frame every time A fori =1: Nframes -MOV (i). CDATA =read (video,i); -P =mov (i). CDATA; theDisp'Current number of frames:'), disp (i); -Imshow (P), title ('Video'); -End
Matlab reading and writing pictures, reading image sequence, read AVI video