Monday, February 22, 2010

Merge a sequence of video images to another

In motion detection you would want to combine your video to the original video. to do this, you combine your original video with the processed video.

the code:

clear all
close all

clc;

disp('Testing Purposes Only....');

fin = 'sampleVideo.avi';

avi = aviread(fin);
% Convert to RGB to GRAY SCALE image.

avi = aviread(fin);
pixels = double(cat(4,avi(1:2:end).cdata))/255; %get all pixels (normalize)
nFrames = size(pixels,4);
%get number of frames


for f = 1:nFrames
pixel(:,:,f) = (rgb2gray(pixels(:,:,:,f))); %convert images to gray scale

end


nrames=f;
for l = 2:nrames
d(:,:,l)=(abs(pixel(:,:,l)-pixel(:,:,1))); %subtract current pixel from background

z(:,:,l)=(abs(pixel(:,:,l)-pixel(:,:,l-1))); %subtract current pixel from previous


%------merge
fg= pixel(:,:,l); %foreground
bg= z(:,:,l); %background

alpha= 0.1;
%alpha
dif = fg-bg;

out = bg + alpha.*dif;

imshow(out);

%--------
drawnow;
end


Results:

1 comment:

  1. hello sir
    im doing project in video compression as PG project . can u please elaborate the steps behind the combine the frames to video.. thanks in advance...

    ReplyDelete