Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Motion estimation vs. background subtraction
Date: Tue, 19 May 2009 13:37:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 63
Message-ID: <guuclt$bg$1@fred.mathworks.com>
References: <fr8o5t$m76$1@fred.mathworks.com> <fr8rvq$rfs$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1242740221 368 172.30.248.38 (19 May 2009 13:37:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 19 May 2009 13:37:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1846903
Xref: news.mathworks.com comp.soft-sys.matlab:540999


> 1) Use a colour camera
> 
> 2) Convert to Normalized RGB to remove the effect of 
> illumination variation.
> 
> 3) Over a protracted period, with no moving target in the  scene, calculate the mean background intensity of each  individual pixel, together with its associated standard 
deviation.
> 
> 4) Select a confidence level (e.g. 3xsigma) whereby the 

> 5) Generate a binary image of all regions that contain 
> pixels that are outside your confidence range (e.g. 
> Pixel_Difference > 3*PixelSigma;
> 
> 6) Track your moving image using something like blob  centroid.
I have a question. I have tried to follow your step but I got some problems with defining pixel that are outside of confidence level.
I will post some code here to explain my ideas:
movie = aviread('fire_sample.avi',[1:300]); 
% reading some avifile file that was acquired by web-cam
%  first 10 frames with no object to obtain background statistics
f1=movie(1).cdata;
........
.........
f10=movie(10).cdata;
f_size = size(f1);             
width = f_size(2);
height = f_size(1);
% estimating mean value intensity for background
sumOfFramesñ+f2+f3+f4+f5+f6+f7+f8+f9+f10; % for estimating background statistics mean
back_mean=sumOfFrames./10; % array for mean values based on 10 frame statistics
back_subtraction=(sumOfFrames-back_mean); %x-x
back_sd=((back_subtraction.^2)./10); %(x-x)^2/10 estimating standard deviation     
D = 3;   
 thresh=D*back_sd; thresh=double(thresh);
for n=1:length(movie);
    fr = movie(n).cdata; 
    fr=double(fr);
red_diff = abs(double(fr(:,:,1)) - double(back_mean(:,:,1))); %defining absolute different in a red channal
green_diff «s(double(fr(:,:,2)) - double(back_mean(:,:,2))); %in a green
blue_diff= abs(double(fr(:,:,3)) - double(back_mean(:,:,3))); %in blue
%here I try to define pixels that are outside of %range
for i=1:width
    for j=1:height
        if (red_diff>thresh(:,:,1))
            M(i,j,1)=1;
        else
            M(i,j,1)=0;
        end
    end
end
% I also do it for green and blue channel then I %want to make smth like this MÊt(3,red %channel, green,blue);
for i=1:width
   for  j=1:height
       if M>2
            CM=1;
        else 
            CM=0;
       end
    end
end

% I think   I will obtain a matrix M where  pixels that are greater then thresh, equal to 1s  and where it is less then thresh pixels value would be zero,  then I should obtain binary mask where threshold would be done as follow if there is a change it least in two color channels we define that it is likely pixel was really changed  
I have a lack of programming so I don't understand why every time when I try to define pixels that are outside of range, M(:,:,1) =0 (all matrix consists of zeros values). Could you please explain my mistakes? Also avi file was normalized before I run foreground detection. I would be appreciate for any help