We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Erasing "Pepper Noise" (Filter)
Page Index Toggle Pages: 1
Erasing "Pepper Noise" (Filter) (Read 1427 times)
Erasing "Pepper Noise" (Filter)
Aug 21st, 2009, 10:50am
 
Hi,
First I'll explain what I'm doing Tongue.
I want to record a white wall with my camera and show anything that enters the frame painted black.

For doing this, I press a key to set a frame as reference and then I compare this image to the next frames.

I compare their brightness pixel by pixel and if the difference is bigger than a set threshold, I paint the pixels black, if not, they remain white.

This works OK, anything I place in front of the camera appears as black.

The problem is, when there are no changes at all, I still see random pixels painted black, it's like "pepper noise". It changes all the time randomly and for what I want to do later I need to erase this noise.

Do any of you know of an "Erosion Filter" or something similar to remove all this random noise??

Thank you in advance Smiley

Re: Erasing "Pepper Noise" (Filter)
Reply #1 - Aug 22nd, 2009, 3:20am
 
Assuming the random noise is electrical or similar noise in the video device and occurs very briefly indeed I wonder whether it would be possible to take an average reading of each pixel, perhaps over 3 frames?  I suspect the biggest problem with that approach would be the performance hit...

A slightly different option might be an 'easing' approach: you have a reference frame, your new frame and an output frame.  If comparison between new and reference pixels > threshold, darken pixel in output frame by a certain amount; otherwise lighten it.  The noise would still have an effect but would have to be persistent over several frames to be properly visible.  The slight downside being a slight delay in responsiveness of the overall system...

Hope this helps in some way - just thinking aloud really...
Re: Erasing "Pepper Noise" (Filter)
Reply #2 - Aug 22nd, 2009, 6:59am
 
Perhaps you want a median filter.
An alternative is to do blob detection to eliminate groups of pixels that are too small.

Actually, the median filter seems to be a good solution: it is rather simple and can be integrated to your phase of pixels beyond a threshold.

The idea: for each pixel (except those on the border), you fill an array of values of the pixel and those around it (3x3, but you can go 5x5, etc.).
You sort the array and take the value in the middle (index 4 for 3x3).
You are supposed to put this value at the same pixel index of the copy of the processed image, but at this stage, you can do your test on threshold and do nothing if below, and put black if above.
Re: Erasing "Pepper Noise" (Filter)
Reply #3 - Aug 23rd, 2009, 12:13pm
 
Hi

I did something similar a while back. I had to read a black marker line from a piece of paper. I found out that testing if x successive pixels in a row were below the threshold was enough to filter out the camera noise (cheap web cam).

http://www.rickigregersen.com/2009/05/02/antrack/

The reason this "low tech" approach worked was because I knew the paper would be white and the line black, so it's simple and fast.
Re: Erasing "Pepper Noise" (Filter)
Reply #4 - Aug 24th, 2009, 10:29am
 
Thanks for every answer Smiley.

In the end I did something like what RickiG suggested, as I didnt really need something too smooth. It worked well enough. The other solutions are probably more powerful, but something simple was good enough for my program.

I'll be back soon with more questions I'm afraid, this is just the beginning of the project and I'm kind of lost xD.

PD: PhilHo, you seem to know something about blob detection Tongue do you know about any tutorial or something like that for beginners? It's exactly what I need to do now. Detect every blob's centroid in the frames my webcam captures.

Thanks again for your help.
Re: Erasing "Pepper Noise" (Filter)
Reply #5 - Aug 24th, 2009, 12:45pm
 
You might want to look at using the JMyron library instead of the Video library; or maybe one of the other video libraries.  I don't use Video (I run a Quicktime alternative that doesn't seem to work with it) and found it easy enough to adapt the example to JMyron...  The 'learning' section seems rather limited, but this seems to be a helpful resource...

Edited:
I'm just having a play around with OpenCV and, once you get past the install process, that also looks like a really good option Wink
Page Index Toggle Pages: 1