To understand the medial filter, maybe it is better if we start in 1D.
Let's suppose the following array:
Also, let's suppose you define a window size of n = 3.
You place yourself in the first value of the array, that is 3. Since your window size is 3, you take the sample you are, one sample to the left and one sample to the right. Since this is the first value, there is no sample to the left, so we will just consider a zero:
From this window, you sort the values from minimum to maximum and get the median (the value in the middle)
In this case, the value in the middle is 2. This is the value you write in the filtered vector a_
Then you go to the next value of a, that is a 2. You take the left sample (which has already been modified) and the right sample
Your sort them and choose the median value (in this case, a 2 again)
1 2 2
So your filtered vector a_ is now
An so on. In the end, you will have a filtered vector a_
A median filter in images works the same way, only in 2D. So you take not only the values (pixels) that are left or right, but all the values that surround the sample (pixel) you are in.
In MATLAB, check medfilt1 and medfilt2 ;) .
doc medfilt1;
doc medfilt2;
Keep coding!
Best Answer