background subtraction
Message-ID:<49dccea5-f515-44cb-9a44-0005bf4a5ad8@w24g2000prd.googlegroups.com>
Subject:
background subtraction
Date:Mon, 8 Dec 2008 09:36:38 +0100
can anyone give me a good robust background subtraction with easy code implementation?
Message-ID:
Subject:
Re: background subtraction
Date:Mon, 8 Dec 2008 18:19:06 +0100
wingraider wrote:
> can anyone give me a good robust background subtraction with easy code
> implementation?
for each pixel
{
foreground[pixel] = input[pixel] - background[pixel];
}
--
Regards,
Martin Leese
E-mail: please@see.Web.for.e-mail.INVALID
Web: http://members.tripod.com/martin_leese/
Message-ID:
Subject:
Re: background subtraction
Date:Tue, 9 Dec 2008 01:09:08 +0100
On Dec 9, 1:19=A0am, Martin Leesewrote: > wingraider wrote: > > can anyone give me a good robustbackgroundsubtractionwith easy code > > implementation? > > for each pixel > { > =A0 =A0 =A0foreground[pixel] =3D input[pixel] -background[pixel]; > > } > > -- > Regards, > Martin Leese > E-mail: ple...@see.Web.for.e-mail.INVALID > Web:http://members.tripod.com/martin_leese/ uhmm..thanks for the reply..i have tried that one,but it doesn't work for me,I'm referring to a foreground cut off type rather than simple differencing. ex. foreground: yyyyyyyyyXXXXXXyyyyyyyyyy background: yyyyyyyyyyyyyyyyyyyyyyyyy result ----------------XXXXXX------------------
Message-ID:
Subject:
Re: background subtraction
Date:Tue, 9 Dec 2008 04:39:44 +0100
On Dec 8, 7:09=A0pm, wingraiderwrote: > On Dec 9, 1:19=A0am, Martin Leese > wrote: > > > wingraider wrote: > > > can anyone give me a good robustbackgroundsubtractionwith easy code > > > implementation? > > > for each pixel > > { > > =A0 =A0 =A0foreground[pixel] =3D input[pixel] -background[pixel]; > > > } > > > -- > > Regards, > > Martin Leese > > E-mail: ple...@see.Web.for.e-mail.INVALID > > Web:http://members.tripod.com/martin_leese/ > > uhmm..thanks for the reply..i have tried that one,but it doesn't work > for me,I'm referring to a foreground cut off type rather than simple > differencing. > > ex. > > foreground: > > yyyyyyyyyXXXXXXyyyyyyyyyy > > background: > > yyyyyyyyyyyyyyyyyyyyyyyyy > > result > > ----------------XXXXXX------------------ ------------------------------------- After inspecting your algorithm, I've come up with: for all x,y: if foreground(x,y) !=3D background(x,y) result(x,y) =3D foreground(x,y) else result(x,y) =3D undefined or null endif end for If you're trying to do something like detect a person walking in front of a static scene (such as a seated crowd and other static clutter) then this kind of thing (background subtraction) doesn't work because the "foreground" pixels are NOT ADDED to the background but instead REPLACE it. So you'd end up with a very broken foreground with holes and corrupt outline. Regards, ImageAnalyst
Message-ID:
Subject:
Re: background subtraction
Date:Tue, 9 Dec 2008 06:50:01 +0100
On Dec 9, 11:39=A0am, ImageAnalystwrote: > On Dec 8, 7:09=A0pm, wingraider wrote: > > > > > On Dec 9, 1:19=A0am, Martin Leese > > wrote: > > > > wingraider wrote: > > > > can anyone give me a good robustbackgroundsubtractionwith easy code > > > > implementation? > > > > for each pixel > > > { > > > =A0 =A0 =A0foreground[pixel] =3D input[pixel] -background[pixel]; > > > > } > > > > -- > > > Regards, > > > Martin Leese > > > E-mail: ple...@see.Web.for.e-mail.INVALID > > > Web:http://members.tripod.com/martin_leese/ > > > uhmm..thanks for the reply..i have tried that one,but it doesn't work > > for me,I'm referring to a foreground cut off type rather than simple > > differencing. > > > ex. > > > foreground: > > > yyyyyyyyyXXXXXXyyyyyyyyyy > > >background: > > > yyyyyyyyyyyyyyyyyyyyyyyyy > > > result > > > ----------------XXXXXX------------------ > > ------------------------------------- > After inspecting your algorithm, I've come up with: > for all x,y: > =A0 if foreground(x,y) !=3Dbackground(x,y) > =A0 =A0 result(x,y) =3D foreground(x,y) > =A0 else > =A0 =A0 result(x,y) =3D undefined or null > =A0 endif > end for > > If you're trying to do something like detect a person walking in front > of a static scene (such as a seated crowd and other static clutter) > then this kind of thing (backgroundsubtraction) doesn't work because > the "foreground" pixels are NOT ADDED to thebackgroundbut instead > REPLACE it. =A0So you'd end up with a very broken foreground with holes > and corrupt outline. > > Regards, > ImageAnalyst yes, I'm trying to detect an object from a static background. the static background is captured without any objects. then i'll put an object in the scene then capture the scene with an object. i want to extract the object from the recently captured scene with the use the background that was captured earlier but simple subtraction won't work for me. i get a very corrupted image out of it.
Message-ID:
Subject:
Re: background subtraction
Date:Tue, 9 Dec 2008 21:28:32 +0100
On Dec 9, 12:50=A0am, wingraiderwrote: > On Dec 9, 11:39=A0am, ImageAnalyst wrote: > > > > > > > On Dec 8, 7:09=A0pm, wingraider wrote: > > > > On Dec 9, 1:19=A0am, Martin Leese > > > wrote: > > > > > wingraider wrote: > > > > > can anyone give me a good robustbackgroundsubtractionwith easy co= de > > > > > implementation? > > > > > for each pixel > > > > { > > > > =A0 =A0 =A0foreground[pixel] =3D input[pixel] -background[pixel]; > > > > > } > > > > > -- > > > > Regards, > > > > Martin Leese > > > > E-mail: ple...@see.Web.for.e-mail.INVALID > > > > Web:http://members.tripod.com/martin_leese/ > > > > uhmm..thanks for the reply..i have tried that one,but it doesn't work > > > for me,I'm referring to a foreground cut off type rather than simple > > > differencing. > > > > ex. > > > > foreground: > > > > yyyyyyyyyXXXXXXyyyyyyyyyy > > > >background: > > > > yyyyyyyyyyyyyyyyyyyyyyyyy > > > > result > > > > ----------------XXXXXX------------------ > > > ------------------------------------- > > After inspecting your algorithm, I've come up with: > > for all x,y: > > =A0 if foreground(x,y) !=3Dbackground(x,y) > > =A0 =A0 result(x,y) =3D foreground(x,y) > > =A0 else > > =A0 =A0 result(x,y) =3D undefined or null > > =A0 endif > > end for > > > If you're trying to do something like detect a person walking in front > > of a static scene (such as a seated crowd and other static clutter) > > then this kind of thing (backgroundsubtraction) doesn't work because > > the "foreground" pixels are NOT ADDED to thebackgroundbut instead > > REPLACE it. =A0So you'd end up with a very broken foreground with holes > > and corrupt outline. > > > Regards, > > ImageAnalyst > > yes, I'm trying to detect =A0an object from a static background. > the static =A0background is captured without any objects. then i'll put > an object in the scene then capture the scene with an object. > > i want to extract the object from the recently captured scene with the > use the background that was captured earlier but simple subtraction > won't work for me. i get a very corrupted image out of it.- Hide quoted t= ext - > > - Show quoted text - ------------------------------------------------------------------- wingraider: Yep, just like I said. Was there some mathematical reason that you thought this method would work? Good luck, ImageAnalyst
Message-ID:
Subject:
Re: background subtraction
Date:Wed, 10 Dec 2008 11:19:16 +0100
wingraider wrote: > yes, I'm trying to detect an object from a static background. > the static background is captured without any objects. then i'll put > an object in the scene then capture the scene with an object. > > i want to extract the object from the recently captured scene with the > use the background that was captured earlier but simple subtraction > won't work for me. i get a very corrupted image out of it. Ah, more background removal, than subtraction. You need to look for masking techniques, green screen matt(e)ing. BugBear
Message-ID:
Subject:
Re: background subtraction
Date:Tue, 9 Dec 2008 06:51:12 +0100
On Dec 9, 11:39=A0am, ImageAnalystwrote: > On Dec 8, 7:09=A0pm, wingraider wrote: > > > > > On Dec 9, 1:19=A0am, Martin Leese > > wrote: > > > > wingraider wrote: > > > > can anyone give me a good robustbackgroundsubtractionwith easy code > > > > implementation? > > > > for each pixel > > > { > > > =A0 =A0 =A0foreground[pixel] =3D input[pixel] -background[pixel]; > > > > } > > > > -- > > > Regards, > > > Martin Leese > > > E-mail: ple...@see.Web.for.e-mail.INVALID > > > Web:http://members.tripod.com/martin_leese/ > > > uhmm..thanks for the reply..i have tried that one,but it doesn't work > > for me,I'm referring to a foreground cut off type rather than simple > > differencing. > > > ex. > > > foreground: > > > yyyyyyyyyXXXXXXyyyyyyyyyy > > >background: > > > yyyyyyyyyyyyyyyyyyyyyyyyy > > > result > > > ----------------XXXXXX------------------ > > ------------------------------------- > After inspecting your algorithm, I've come up with: > for all x,y: > =A0 if foreground(x,y) !=3Dbackground(x,y) > =A0 =A0 result(x,y) =3D foreground(x,y) > =A0 else > =A0 =A0 result(x,y) =3D undefined or null > =A0 endif > end for > > If you're trying to do something like detect a person walking in front > of a static scene (such as a seated crowd and other static clutter) > then this kind of thing (backgroundsubtraction) doesn't work because > the "foreground" pixels are NOT ADDED to thebackgroundbut instead > REPLACE it. =A0So you'd end up with a very broken foreground with holes > and corrupt outline. > > Regards, > ImageAnalyst yes, I'm trying to detect an object from a static background. the static background is captured without any objects. then i'll put an object in the scene then capture the scene with an object. i want to extract the object from the recently captured scene with the use the background that was captured earlier but simple subtraction won't work for me. i get a very corrupted image out of it.
Message-ID:
Subject:
Re: background subtraction
Date:Wed, 10 Dec 2008 14:41:04 +0100
"wingraider"wrote in message news:c0f71bf8-dadd-4784-9be6-2b9577abc83a@i24g2000prf.googlegroups.com... On Dec 9, 11:39 am, ImageAnalyst wrote: > On Dec 8, 7:09 pm, wingraider wrote: > > > > > On Dec 9, 1:19 am, Martin Leese > > wrote: > > > > wingraider wrote: > > > > can anyone give me a good robustbackgroundsubtractionwith easy code > > > > implementation? > > > > for each pixel > > > { > > > foreground[pixel] = input[pixel] -background[pixel]; > > > > } > > > > -- > > > Regards, > > > Martin Leese > > > E-mail: ple...@see.Web.for.e-mail.INVALID > > > Web:http://members.tripod.com/martin_leese/ > > > uhmm..thanks for the reply..i have tried that one,but it doesn't work > > for me,I'm referring to a foreground cut off type rather than simple > > differencing. > > > ex. > > > foreground: > > > yyyyyyyyyXXXXXXyyyyyyyyyy > > >background: > > > yyyyyyyyyyyyyyyyyyyyyyyyy > > > result > > > ----------------XXXXXX------------------ > > ------------------------------------- > After inspecting your algorithm, I've come up with: > for all x,y: > if foreground(x,y) !=background(x,y) > result(x,y) = foreground(x,y) > else > result(x,y) = undefined or null > endif > end for > > If you're trying to do something like detect a person walking in front > of a static scene (such as a seated crowd and other static clutter) > then this kind of thing (backgroundsubtraction) doesn't work because > the "foreground" pixels are NOT ADDED to thebackgroundbut instead > REPLACE it. So you'd end up with a very broken foreground with holes > and corrupt outline. > > Regards, > ImageAnalyst >yes, I'm trying to detect an object from a static background. >the static background is captured without any objects. then i'll put >an object in the scene then capture the scene with an object. > >i want to extract the object from the recently captured scene with the >use the background that was captured earlier but simple subtraction >won't work for me. i get a very corrupted image out of it. If these images are captured then you're going to get subtle differences in the backgrounds. This would be due to the tiniest camera shake, and most importantly the type of compression the image has undergone to get to the computer. Also, if a limit is placed on the amount of data because of streaming video, then a single change in a part of the image could effect the whole image. You could check for pixels that are NEARLY the same within some threshold, or try filtering the images before the testing to removing any high frequency noise.
Message-ID:<8e3c0e1b-2c6b-4d3f-a004-a6d02e4da0c8@r13g2000vbp.googlegroups.com>
Subject:
Re: background subtraction
Date:Fri, 12 Dec 2008 09:35:15 +0100
Hello,
Once I was writing some motion detection algorithms and one of them
was based on similar technique =96 subtracting background from current
video frame to locate moving object. You may check some ideas on Code
Project:
http://www.codeproject.com/KB/audio-video/Motion_Detection.aspx
To do what you need (get an object) you may need differencing,
thresholding and masking:
1) Get difference image:
for each pixel
{
difference[pixel] =3D input[pixel] - background[pixel];
}
2) Threshold difference
for each pixel
{
difference[pixel] =3D (difference[pixel] > threshold ) ? 1 : 0;
}
3) Masking =96 remove background from input image.
for each pixel
{
If (difference[pixel] =3D=3D 0 )
input[pixel] =3D 0;
}
Since you may get some noise from your camera, I would suggest using
some noise suppression techniques between 2nd and 3rd steps. For
example math morphology could work (erosion, opening).
With best regards,
Andrew
http://www.aforgenet.com
>
> yes, I'm trying to detect =A0an object from a static background.
> the static =A0background is captured without any objects. then i'll put
> an object in the scene then capture the scene with an object.
>
> i want to extract the object from the recently captured scene with the
> use the background that was captured earlier but simple subtraction
> won't work for me. i get a very corrupted image out of it.- Hide quoted t=
ext -
>
> - Show quoted text -
Message-ID:<5efcd108-d439-4b05-b5f8-9b6aa15174fa@e18g2000yqo.googlegroups.com>
Subject:
Re: background subtraction
Date:Fri, 12 Dec 2008 14:34:47 +0100
On Dec 12, 3:35=A0am, Andrew Kirillovwrote: > Hello, > > Once I was writing some motion detection algorithms and one of them > was based on similar technique =96 subtracting background from current > video frame to locate moving object. You may check some ideas on Code > Project:http://www.codeproject.com/KB/audio-video/Motion_Detection.aspx > > To do what you need (get an object) you may need differencing, > thresholding and masking: > 1) Get difference image: > for each pixel > { > =A0 =A0 =A0difference[pixel] =3D input[pixel] - background[pixel]; > > } > > 2) Threshold difference > for each pixel > { > =A0 =A0 =A0difference[pixel] =3D (difference[pixel] > threshold ) ? 1 : 0= ; > > } > > 3) Masking =96 remove background from input image. > for each pixel > { > =A0 =A0 If (difference[pixel] =3D=3D 0 ) > =A0 =A0 =A0 =A0 input[pixel] =3D 0; > > } > > Since you may get some noise from your camera, I would suggest using > some noise suppression techniques between 2nd and 3rd steps. For > example math morphology could work (erosion, opening). > > With best regards, > Andrew > > http://www.aforgenet.com > > > > > > > yes, I'm trying to detect =A0an object from a static background. > > the static =A0background is captured without any objects. then i'll put > > an object in the scene then capture the scene with an object. > > > i want to extract the object from the recently captured scene with the > > use the background that was captured earlier but simple subtraction > > won't work for me. i get a very corrupted image out of it.- Hide quoted= text - > > > - Show quoted text -- Hide quoted text - > > - Show quoted text - ---------------------------------------------------------------------------= - Andrew: And what did you do when the foreground object was darker than your background, or the same intensity as your background? You'd have holes in your thresholded object. Did you simply do a hole fill? Does that work OK? What about if those regions are at the edge of the object so that a hole fill won't work? What did you do then? Regards, ImageAnalyst
Message-ID:<322235b1-7d48-4405-9111-ab2f6f1a9c11@v5g2000prm.googlegroups.com>
Subject:
Re: background subtraction
Date:Fri, 12 Dec 2008 20:21:13 +0100
Sorry, I did not make my difference idea clear. I take absolute difference, which is |input - background|. So even if object is darker, it is not issue. The issue appears only when object's intensity is close to background. Then the result will be as you've described. With best regards, Andrew http://www.aforgenet.com > > -------------------------------------------------------------------------= --=AD- > Andrew: > And what did you do when the foreground object was darker than your > background, or the same intensity as your background? =A0You'd have > holes in your thresholded object. =A0Did you simply do a hole fill? > Does that work OK? =A0What about if those regions are at the edge of the > object so that a hole fill won't work? =A0What did you do then? > Regards, > ImageAnalyst- Hide quoted text - > > - Show quoted text -
Message-ID:<6ns7k4pol82j5fh96dud4pdqk6f0pv5280@4ax.com>
Subject:
Re: background subtraction - with shadows
Date:Sat, 13 Dec 2008 19:12:18 +0100
Andrew, thanks for the good concise algorithm. I am doing about the same thing, with decent results.I am building a scorekeeping system for car races, using video input to detect the cars as they cross the finish line, recognize each car by car number, color, and any other features I can find, and keep track of times and lap counts for each car. Currently, all major car races (NASCAR, Indy car, Formula 1) require the cars to carry radio transponders to identify the cars to a scoring computer, which is expensive and trouble-prone. I'm trying to use video recognition to replace the transponders. I am using the PIL (Python Image Library) for my project; it's easy to use and free, but doesn't have as many features as other packages such as 'blob detection', and Python is significantly slower than other software, so I may have a challenge working in real-time. The first few steps of my process are: 1) capture an empty 'background' image (and refresh it on occasion) 2) for each subsequent frame, get a 'difference' image 3) use a few filters to remove 'noise', adjust to changing light conditions, etc. 4) if the pixel count is less than X, there's 'nothing more to see here'; wait for the next frame; otherwise ... 5) generate a 'mask' from the 'difference' image 6) 'solidify' the mask: fill in holes and crevasses 7) use the mask to cut-and-paste the new object (one or more cars, in my case) from the scene. This works pretty well ... but I am not doing a very good job of identifying, and masking off, shadows, which of course give misleading information about the car's size, shape, and colors. I have some ugly code to compare the edges of the mask to the background: if a pixel is X percent darker than the background, it *might* be a shadow. Has anyone else done a decent job of separating features from shadows? Gary Davis earth to gary at earth link period n e t On Fri, 12 Dec 2008 00:35:15 -0800 (PST), Andrew Kirillovwrote: >Hello, > >Once I was writing some motion detection algorithms and one of them >was based on similar technique – subtracting background from current >video frame to locate moving object. You may check some ideas on Code >Project: >http://www.codeproject.com/KB/audio-video/Motion_Detection.aspx [snip]
Message-ID:<472509e1-8580-455e-b82d-b47af1ed925a@h16g2000yqj.googlegroups.com>
Subject:
Re: background subtraction - with shadows
Date:Sat, 13 Dec 2008 22:43:51 +0100
On Dec 13, 1:12=A0pm, Pioneerwrote: > Andrew, thanks for the good concise algorithm. > I am doing about the same thing, with decent results. > > > I am building a scorekeeping system for car races, using video input > to detect the cars as they cross the finish line, recognize each car > by car number, color, and any other features I can find, and keep > track of times and lap counts for each car. =A0Currently, all major car > races (NASCAR, Indy car, Formula 1) require the cars to carry radio > transponders to identify the cars to a scoring computer, which is > expensive and trouble-prone. =A0I'm trying to use video recognition to > replace the transponders. > I am using the PIL (Python Image Library) for my project; it's easy to > use and free, but doesn't have as many features as other packages such > as 'blob detection', and Python is significantly slower than other > software, so I may have a challenge working in real-time. > > > The first few steps of my process are: > 1) capture an empty 'background' image (and refresh it on occasion) > 2) for each subsequent frame, get a 'difference' image > 3) use a few filters to remove 'noise', adjust to changing light > conditions, etc. > 4) if the pixel count is less than X, there's 'nothing more to see > here'; wait for the next frame; otherwise ... > 5) generate a 'mask' from the 'difference' image > 6) 'solidify' the mask: fill in holes and crevasses > 7) use the mask to cut-and-paste the new object (one or more cars, in > my case) from the scene. > > This works pretty well ... but I am not doing a very good job of > identifying, and masking off, shadows, which of course give misleading > information about the car's size, shape, and colors. =A0I have some ugly > code to compare the edges of the mask to the background: if a pixel is > X percent darker than the background, it *might* be a shadow. > > Has anyone else done a decent job of separating features from shadows? > > Gary Davis > earth to gary at earth link period n e t > > On Fri, 12 Dec 2008 00:35:15 -0800 (PST), Andrew Kirillov > >wrote: > >Hello, > > >Once I was writing some motion detection algorithms and one of them > >was based on similar technique =96 subtracting background from current > >video frame to locate moving object. You may check some ideas on Code > >Project: > >http://www.codeproject.com/KB/audio-video/Motion_Detection.aspx > > [snip] -------------------------------------------- Pioneer: Just 3 days ago I answered something like this in the MATLAB newsgroup: http://tinyurl.com/5uvtvh I think that method could work but you need to look at surrounding pixels and see if they are all down by the same percentage. Because otherwise, ANY dark pixel could be a percentage of the background (for example, it a black car came into view). That's why you need to check a bunch of surrounding pixels to see if they are all about the same percentage down. But otherwise, with a few tweaks and things, it could work. Regards, ImageAnalyst
Message-ID:<6qsgk2Fe8qapU1@mid.individual.net>
Subject:
Re: background subtraction - with shadows
Date:Wed, 17 Dec 2008 15:28:16 +0100
Pioneer wrote: > Has anyone else done a decent job of separating features from shadows? Have you considered using a calibrated, stereo vision system? Shadows always stay on the ground, but most pixels on the car will be above the ground. 3D might help your classification, too, for example you could use depth discontinuities to tell whether your blob was a single car or one car occluding another one. Of course, you'd have to solve the correspondence problem, but I'd have thought that the finish line around a race track would have plenty of good features to use as markers. Cheers mark-r
Message-ID:<2747624c-c7a7-467a-a3c4-579ed4e67cf8@r37g2000prr.googlegroups.com>
Subject:
Re: background subtraction
Date:Wed, 17 Dec 2008 11:38:16 +0100
On Dec 12, 4:35=A0pm, Andrew Kirillovwrote: > Hello, > > Once I was writing some motion detection algorithms and one of them > was based on similar technique =96 subtractingbackgroundfrom current > video frame to locate moving object. You may check some ideas on Code > Project:http://www.codeproject.com/KB/audio-video/Motion_Detection.aspx > > To do what you need (get an object) you may need differencing, > thresholding and masking: > 1) Get difference image: > for each pixel > { > =A0 =A0 =A0difference[pixel] =3D input[pixel] -background[pixel]; > > } > > 2) Threshold difference > for each pixel > { > =A0 =A0 =A0difference[pixel] =3D (difference[pixel] > threshold ) ? 1 : 0= ; > > } > > 3) Masking =96 removebackgroundfrom input image. > for each pixel > { > =A0 =A0 If (difference[pixel] =3D=3D 0 ) > =A0 =A0 =A0 =A0 input[pixel] =3D 0; > > } > > Since you may get some noise from your camera, I would suggest using > some noise suppression techniques between 2nd and 3rd steps. For > example math morphology could work (erosion, opening). > > With best regards, > Andrew > > http://www.aforgenet.com > > > > > yes, I'm trying to detect =A0an object from a staticbackground. > > the static =A0backgroundis captured without any objects. then i'll put > > an object in the scene then capture the scene with an object. > > > i want to extract the object from the recently captured scene with the > > use thebackgroundthat was captured earlier but simplesubtraction > > won't work for me. i get a very corrupted image out of it.- Hide quoted= text - > > > - Show quoted text - thanks andrew for that logic flow,i'm now having trouble on threshold selection. is there any way to automatically select thresold value without going to grayscaling the image and finding the minima and maxima of the histogram?



RSS News Feed