From: ImageAnalyst on
On Mar 22, 8:27 am, "Kevin " <kanwalre...(a)gmail.com> wrote:
> Guys even if somebody could tell me how to apply median filter to my code or other kind of filteration which will prevent all the small pixels to appear in the videos.
>
> Thanks
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Come on Kevin - it's not that hard. Did you look at the help
documentation for medfilt2()? It has an example in it. Here's
another one - it should be very straightforward to apply this to your
code:

% Read in standard MATLAB demo image.
grayImage = imread('cameraman.tif');
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', 20);
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.

% Add salt and pepper noise.
noisyImage = imnoise(grayImage, 'salt & pepper', .1);
subplot(2, 2, 2);
imshow(noisyImage, []);
title('Image with salt and pepper noise added', 'FontSize', 20);

denoisedImage = medfilt2(noisyImage, [3 3]);
subplot(2, 2, 3);
imshow(denoisedImage, []);
title('Median Filtered Image', 'FontSize', 20);


However I still think this is not heading toward an optimal solution
and I still think you should look at the other background estimation
methods I refered you to. Or simply just take the mode of all the
frames as your background (since you have a stationary camera) and
subtract that from all the other frames. Then threshold on
differences, say 5 gray levels because anything that changes less than
that is just noise (quivering tree leaves, etc.)
From: Kevin on
ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <560620dd-4001-4cc0-ab18-fcc387a74a77(a)z4g2000yqa.googlegroups.com>...
> On Mar 22, 8:27 am, "Kevin " <kanwalre...(a)gmail.com> wrote:
> > Guys even if somebody could tell me how to apply median filter to my code or other kind of filteration which will prevent all the small pixels to appear in the videos.
> >
> > Thanks
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------
> Come on Kevin - it's not that hard. Did you look at the help
> documentation for medfilt2()? It has an example in it. Here's
> another one - it should be very straightforward to apply this to your
> code:
>
> % Read in standard MATLAB demo image.
> grayImage = imread('cameraman.tif');
> subplot(2, 2, 1);
> imshow(grayImage, []);
> title('Original Grayscale Image', 'FontSize', 20);
> set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
>
> % Add salt and pepper noise.
> noisyImage = imnoise(grayImage, 'salt & pepper', .1);
> subplot(2, 2, 2);
> imshow(noisyImage, []);
> title('Image with salt and pepper noise added', 'FontSize', 20);
>
> denoisedImage = medfilt2(noisyImage, [3 3]);
> subplot(2, 2, 3);
> imshow(denoisedImage, []);
> title('Median Filtered Image', 'FontSize', 20);
>
>
> However I still think this is not heading toward an optimal solution
> and I still think you should look at the other background estimation
> methods I refered you to. Or simply just take the mode of all the
> frames as your background (since you have a stationary camera) and
> subtract that from all the other frames. Then threshold on
> differences, say 5 gray levels because anything that changes less than
> that is just noise (quivering tree leaves, etc.)

Actually I did try the median filter and got the following results:

http://img692.imageshack.us/img692/7352/screenhunter09mar221953.gif

From the image you can see that the there are few disturbances but in the foreground cars are not well defined.

**************************************************************
Code:
for n = 1:length(source)
nframe = double(source(n).cdata); % read in frame
[fr_bw, foreground, mean, sd] = background_subtraction(nframe,mean,w,sd,alpha,threshold,C,D,M,width,height);
L = medfilt2(foreground, [10 10]);
figure(1),subplot(1,2,1),imshow(uint8(fr_bw))
subplot(1,2,2),imshow(uint8(L))
end
***************************************************************

________________________________
Or simply just take the mode of all the frames as your background (since you have a stationary camera) and subtract that from all the other frames. Then threshold on
differences, say 5 gray levels because anything that changes less than that is just noise (quivering tree leaves, etc.)
_____________________________

Could explain this part again please or even give me a code snipet please.
From: ImageAnalyst on
Kevin:
The mode is the most frequently occurring value. Now let's
concentrate on a particular pixel in your image (it doesn't matter
which one). Now let's say that for frames 1-1000, and frames 1100 -
3000 the scene was just a constant unchanging view of the street, and
that the pixel value was 150. Now let's say that during frames 1000 -
1100 a dark car was passing through, and that the intensity of the
pixel during those frames was 70. Now, what do you think would be a
good value for the background for that pixel? It only takes 2 values:
70 and 150. Do you think 150 would be a good guess for the
background? Or how about 70? Well since the pixel spent most of its
time at 150 and only a short time at 70, don't you think that 150
would be the best choice since it was the most commonly occurring
value over all frames? Now recall the definition of mode - the most
commonly occurring value. 150 is the mode! So doesn't it make perfect
intuitive sense that the mode would be the best choice for the
background? And this would be valid for all pixels in the image. So
just use the MATLAB functions to calculate the mode image and use
that. Does that make sense now?
From: Kevin on
ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <14b96cb6-9426-4a5f-84a8-23ee9c9c4f4e(a)t23g2000yqt.googlegroups.com>...
> Kevin:
> The mode is the most frequently occurring value. Now let's
> concentrate on a particular pixel in your image (it doesn't matter
> which one). Now let's say that for frames 1-1000, and frames 1100 -
> 3000 the scene was just a constant unchanging view of the street, and
> that the pixel value was 150. Now let's say that during frames 1000 -
> 1100 a dark car was passing through, and that the intensity of the
> pixel during those frames was 70. Now, what do you think would be a
> good value for the background for that pixel? It only takes 2 values:
> 70 and 150. Do you think 150 would be a good guess for the
> background? Or how about 70? Well since the pixel spent most of its
> time at 150 and only a short time at 70, don't you think that 150
> would be the best choice since it was the most commonly occurring
> value over all frames? Now recall the definition of mode - the most
> commonly occurring value. 150 is the mode! So doesn't it make perfect
> intuitive sense that the mode would be the best choice for the
> background? And this would be valid for all pixels in the image. So
> just use the MATLAB functions to calculate the mode image and use
> that. Does that make sense now?

Mr ImageAnalyst SIR it does make sense now!

I checked the help for 'mode' and brings up examples but not too sure on how to calculate the mode image?

Example:

I = imread('image.jpg');
m = mode(I);

Thanks
Kevin