How to update a background model in motion detection

2 views (last 30 days)
Hi I am implementing an equation for my abckground model. I have its mathematical form and i believed i implemented it on MTALAB but there seems to be a problem. Either there is some thing missing in my synatx so i was wondering if any one out there can ahve a lookl and correct mr or guide me. Basically what it does is the if equation get satisifes it fills 1on that location (1 in image pixel) else it put 0 in that location.This is my equation
imageGray-meanofIMage>3max(imageVariance,cameranoiseVariance)
if true
if(abs(imGray(row_loop,col_loop)-state.meanIm(row_loop,col_loop))>(3*max((state.varIm(row_loop,col_loop)),state.cameraNoiseVar)))
relutantIm=1;
else
resultantIm=0;
end
Now what i recieve is image that contains all zeros where as it should have some 1 i am sure about that.My values are right since i have a refrence to cross check it i believe something is wrong with my syntax.
Any helps are appreciated

Accepted Answer

Image Analyst
Image Analyst on 14 Apr 2014
Edited: Image Analyst on 14 Apr 2014
You want resultantIm to be an entire image, right? Not just one number? So do this:
resultantIm = abs(imGray-state.meanIm) > 3*max(state.varIm,state.cameraNoiseVar);
No need for looping over row_loop and col_loop. You can do it all in one line. resultantIm is a logical (binary) image - 0 or 1, or false or true.
To get the masked foreground
foregroundImage = imGray; % Initialize
foregroundImage(~resultantIm) = 0; % Blacken background.
To get the background image:
backgroundImage = imGray; % Initialize
backgroundImage(resultantIm) = 0; % Blacken foreground.

More Answers (0)

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!