Matlab reading and writing pictures, reading image sequence, read AVI video

Source: Internet
Author: User
Tags bmp image cdata

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.