Login  Register

Re: median filter that preserves peaks

Posted by Kenneth Sloan-2 on Sep 07, 2013; 5:19am
URL: http://imagej.273.s1.nabble.com/median-filter-that-preserves-peaks-tp5004693p5004710.html

The nice thing about filters like the MedianFilter is that once you have committed to that style, you can implement ANY function of the values inside the window.  This is what separates Median from more signal-processing-inspired methods like Mean.  Median is a frank "spatial domain" operation, with no clear partner in the Fourier domain.  Given a 5x5 window, say, you have 25 values - and are free to compute "anything you want to" from those 25 values.

To completely solve this problem, I propose a small suite of programs, all modified in roughly the same way.  The idea is that small, local fluctuations are "noise" but macroscopic major features are "signal".  

The basic idea is: if the central value in a window is the MIN or MAX within the window, LEAVE IT ALONE.  Otherwise - do the usual thing.

So, XXXFilter becomes:

for (x = 0, width)
 for (y = 0, height)
   {
     gatherWindowAndCompute(x,y,windowW, windowH)
     if (MinOrMax(input(x,y)) output(x,y) = input(x,y)
     else output(x,y) =  XXX(window);
   }

I hope that communicates the idea.

Now…to fully implement what the OP wants, I suggest implementing MedianFilter and also MeanFilter.

Apply this new MedianFilter first - this will ALMOST do what you want, but it will accentuate the peaks and valleys (the region surrounding the min/max will be muted, but the min/max will be isolated spikes.

Apply the new MeanFilter to smooth things out again.  The peaks/valleys will stay where they are, and the surrounding neighborhood will ramp up/down smoothly.

What you should get will be a processed image that is generally smoother, but retains all the peaks/valleys from the original.  Local wiggles will have disappeared.

For full generality, you might want different window sizes for the MinOrMax computation and the XXX computation.  That is - you might compute the Median everywhere in a 5x5 window, except where the central pixel is the min/max over a 10x10 window.

I'll probably have someone implement this in my ImageJ class, this Spring - but "feel free to steal this idea - just remember where you got it".  I won't have time to pursue it until then…

So…is this new?  is it useful?  I don't know the answer to either question, yet.

Of course, if your peak really IS noise, then you are…what's the technical phrase?…screwed.

The trouble with "variation diminishing" operators is that they, well… "diminish variation".  There's really not much you can do about that, short of *understanding* the image.  Sadly, low level operators like "medianFilter" don't do much in the way of "understanding".


--
Kenneth Sloan
[hidden email]


On Sep 6, 2013, at 16:18 , Neil Fazel <[hidden email]> wrote:

> Thanks. I will look into that.
>
> I have attached a montage of 3 profile plots using 1) the original image, 2) image after applying median filter with radius 0.5, and 3) image after median filter with radius 1. You can see how the Y axis maximum of the plots goes from 3.28 to 3.15 to 3.13; the high frequency component has been reduced (good) at the same time that the peaks have been flattened (bad).
>
> I guess what I'm looking for is a filter that replaces local outliers (i.e. outliers in a neighborhood 2-3 pixels in each direction) with the median, but preserves them if they remain outliers in a larger neighborhood, which indicates that they are not noise but actual peak signal.
>
> Neil
>
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> <median filter flattens peaks somewhat.png>

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