Reputation: 1
I am trying to subtract two images using absdiff function ,to extract moving object, it works good but sometimes background appears in front of foreground. This actually happens when the background and foreground colors are similar,Is there any solution to overcome this problem? It may be description of the problem above not enough; so I attach images in the following link . Thanks..
Upvotes: 0
Views: 1409
Reputation: 237
You can use some pre-processing techniques like edge detection and some contrast stretching algorithm, which will give you some extra information for subtracting the image. Since color is same but new object should have texture feature like edge; if the edge gets preserved properly then when performing image subtraction you will obtain the object.
Process flow:
Upvotes: 3
Reputation: 2462
There isn't enough information to formulate a complete solution to your problem but there are some tips I can offer:
First, prefilter the input and background images using a strong median (or gaussian) filter. This will make your results much more robust to image noise and confusion from minor, non-essential detail (like the horizontal lines of your background image). Unless you want to detect a single moving strand of hair, you don't need to process the raw pixels.
Next, take the advice offered in the comments to test all 3 color channels as opposed to going straight to grayscale.
Then create a grayscale image from the the max of the 3 absdiffs done on each channel.
Then perform your closing and opening procedure.
I don't know your requirements so I can't take them into account. If accuracy is of the utmost importance. I'd use the median filter on input image over gaussian. If speed is an issue I'd scale down the input images for processing by at least half, then scale the result up again. If the camera is in a fixed position and you have a pre-calibrated background, then the current naive difference method should work. If the system has to determine movement from a real world environment over an extended period of time (moving shadows, plants, vehicles, weather, etc) then a rolling average (or gaussian) background model will work better. If the camera is moving you will need to do a lot more processing, probably some optical flow and/or fourier transform tests. All of these things need to be considered to provide the best solution for the application.
Upvotes: 1