
In my previous post I describe some way to detect Edge of an Image by MatLab .
In this post I will describe one way to process a video .
Video are just a series of still images and it changes so fast that we can not detect the single image .
Basically this images are called frames , and a video has constant frames rate measured in Second
basically 15 , 20 or 30 fps (frame per second ).
The idea behind the video processing is to capture the frame , it is now raw image . Before futher processing we have make it as a standard image , then move forward . It is now just image processing . After that finally we make video file with the processed images (images_>frame) .
Here is the following simle code of video Processing :-
it will take an avi (audio Video Interleaved)file as an input , capture the frame into image
then use this image for edge detection and finally make the output Video . Lets Enjoy it ... ...
%% It is for Avi file , that keep in working directory
Vidin = 'sample.avi' ;
Vidout = 'out.avi';
% give all the properties of the video file belongs
fileinfo = aviinfo(Vidin);
nframes = fileinfo.NumFrames;
aviobj = avifile(Vidout, 'compression', 'none', 'fps',20);
for i = 1:nframes
%Read frames from input video
mov_in = aviread(Vidin,i);
% frame to image
im_in = frame2im(mov_in);
% RGB TO Gary Image
imf_out = rgb2gray(im_in);
% Edge detection with canny
canny_im = edge(imf_out,'canny');
figure(2);
imagesc(canny_im);
axis('square');
colormap('gray');
[X, map] = gray2ind(canny_im, 16);
grapmap = gray(256);
frm = im2frame(X , grapmap);
aviobj = addframe(aviobj,frm);
end;
aviobj = close(aviobj);
return;
Vidin = 'sample.avi' ;
Vidout = 'out.avi';
% give all the properties of the video file belongs
fileinfo = aviinfo(Vidin);
nframes = fileinfo.NumFrames;
aviobj = avifile(Vidout, 'compression', 'none', 'fps',20);
for i = 1:nframes
%Read frames from input video
mov_in = aviread(Vidin,i);
% frame to image
im_in = frame2im(mov_in);
% RGB TO Gary Image
imf_out = rgb2gray(im_in);
% Edge detection with canny
canny_im = edge(imf_out,'canny');
figure(2);
imagesc(canny_im);
axis('square');
colormap('gray');
[X, map] = gray2ind(canny_im, 16);
grapmap = gray(256);
frm = im2frame(X , grapmap);
aviobj = addframe(aviobj,frm);
end;
aviobj = close(aviobj);
return;