Login  Register

Re: Mode filter

Posted by Michael Schmid on Aug 23, 2017; 6:18pm
URL: http://imagej.273.s1.nabble.com/Mode-filter-tp5019225p5019253.html

On 18/08/2017 09:21, Richard wrote:
 > Hie Everyone
 > Is there a mode filter for imagej?. I can only find mean, median etc.
_______________________________________________________________________

Hi Richard,

well, I think a 'true' mode filter is not of much value, the 'mode' as
the most frequently occurring value makes sense only if there are very
many pixels included, not for a few pixels in a given surrounding (like
in a typical filter operation with small radius, such as typically used
for the 'median', 'mean', etc. filters).

E.g., if the pixel values in a given 3x3 neighborhood are
   10, 10, 21, 23, 24, 25, 26, 27, 29
the mode filter would report 10
A median would give you 24.
If the filter is meant for removing outliers, I think it should discard
the two '10' values (maybe also the '21' and '29') and give you 25.

So a better algorithm might be finding the smallest interval where some
given fraction of pixels is situated (about 50% for small samples like
3x3, maybe 30% for very large samples) and then taking the average of
the pixel values in that range.  It would be a bit like finding the peak
(mode) of a smoothed histogram.  If this fraction of pixels is less than
50% such a filter might also do some edge-preserving smoothing (probably
resulting in more noisy edges than other edge-preserving smoothing
algorithms).

Some ideas for the algorithm for such a filter:
- first sorting the pixel values in a given neighborhood (which gives
you a list as my example above)
- then step through the array taking the differences between the
(i+n*percentage)-th and i-th element, and finding the minimum of these
percentages. In the example above, assuming n*percentage=4 (4/9 = 44%)
the differences are
   23-10= 13, 24-10= 14,  25-21= 4,  26-23= 3,  27-24= 3,  29-25= 4
Both '3' values are minima, corresponding to averages for the given
intervals of
   (23+24+25+26)/4 = 24.5    and
   (24+25+26+27)/4 = 25.5

This looks almost perfect, but if you have the following values:
    10, 10, 21, 23, 24, 26, 27, 28, 29
you would get 27.5, which is probably higher what a human would consider
the optimum result (but still slightly better than the median, which is 24).

--

An alternative you could also have a look at is Lee's Sigma filter:
   http://imagej.net/plugins/sigma-filter.html


Michael

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html