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:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwZoqBDBDRPPjt-wkOMLPnX5f2FSIbLk3as1VhsV_m0xvEyw7FRSXUWYLyR0OSdzLEVJDaAXOCZXhXPmnmLFzrrit7KHOSRRtpxOWfkSCRgWF9_RvZgjjgs_ry6sPuv91VCYjHWsbSN0vr/s400/merge2.jpg)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiv3N1IwRNcugB7YR-xrBM1KTS5hyphenhyphenw8gf7iw6jZGk4RQeskh6E40m993suZxwTptVu7FTIXJ89rEHx0qjYkg_mN8qdnIwqO62S7i0412MQ7p8v1J9bgXjPdPkYL-3yVaQ90Ayrez29_CZL5/s400/merge.jpg)
hello sir
ReplyDeleteim doing project in video compression as PG project . can u please elaborate the steps behind the combine the frames to video.. thanks in advance...