Saturday, May 22, 2010

medium complexity background subtraction using approximate median



In this method the previous N frames of video are buffered, and the background is calculated as the median of buffered frames. The problem is the background is cleared of all objects after few frames to show a cleared background.

Median filtering has been shown to be very robust and to have performance comparable to higher complexity methods. However, storing and processing many frames of video (as is often required to track slower moving objects) requires an often prohibitively large amount of memory. This can be alleviated somewhat by storing and processing frames at a rate lower than the frame rate— thereby lowering storage and computation requirements at the expense of a slower adapting background.

The approximate median method works as such: if a pixel in the current frame has a value larger than the corresponding background pixel, the background pixel is incremented by 1. Likewise, if the current pixel is less than the background pixel, the background is decremented by one. In this way, the background eventually converges to an estimate where half the input pixels are greater than the background, and half are less than the background—approximately the median (convergence time will vary based on frame rate and amount movement in the scene.)




for i = 2:length(source)

fr = source(i).cdata;
fr_bw = rgb2gray(fr); % convert frame to grayscale

fr_diff = abs(double(fr_bw) - double(bg_bw)); % avoid negative overflow

for j=1:width
for k=1:height

if ((fr_diff(k,j) > thresh))
fg(k,j) = fr_bw(k,j);
else
fg(k,j) = 0;
end

if (fr_bw(k,j) > bg_bw(k,j))
bg_bw(k,j) = bg_bw(k,j) + 1;
elseif (fr_bw(k,j) <>
bg_bw(k,j) = bg_bw(k,j) - 1;
end

end
end

figure(1),subplot(3,1,1),imshow(fr)
subplot(3,1,2),imshow(uint8(bg_bw))
subplot(3,1,3),imshow(uint8(fg))
end

12 comments:

  1. these example are not usable ... elseif (fr_bw(k,j) <>

    ReplyDelete
  2. these are not examples, just portions of the code ive used...

    ReplyDelete
  3. do you have code of kalman ???? or any moving object tracking code??? can u plz give some examples for object tracking using background separation.

    ReplyDelete
  4. Hai, Thank you, for uploading this Code.
    But, i have error while iam run this code,
    the error is...
    elseif (fr_bw(k,j) <>
    Pl kindly give the correct changes in this statement.

    ReplyDelete
  5. Hi. Please. Can you help me send the full code of this method?
    my email: locq91@gmail.com

    ReplyDelete
  6. Hi. Please. Can you help me send the full code of this method?
    my email: ytzhakh@gmail.com

    ReplyDelete
  7. Can you help me send the full code of this method?
    my email: dipt912@gmail.com

    ReplyDelete
  8. Can you help me send the full code of this method?
    my email: bieshsp1992@gmail.com@gmail.com

    ReplyDelete
  9. Can you help me send the full code of this method?
    my email: oritrabel@gmail.com

    ReplyDelete
  10. Can you help me send the full code of this method?
    my email: harishcoole@gmail.com

    ReplyDelete
  11. Can you help me send the full code of this method?
    my email: shikhamangal.muskan56@gmail.com

    ReplyDelete