Does ImageJ have a plugin that does what the median filter does, but also preserves peaks? The median filter, even at a radius of 2, tends to flatten sharp peaks.
Thanks, Neil -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hmm, I ask me what you mean with "does what the median filter does"? The median filter is an edge preserving (I would even say an edge-producing) filter. The impact of it is to remove spikes and holes smaller then the filter size.
Am 06.09.2013 um 01:12 schrieb Neil Fazel <[hidden email]>: > Does ImageJ have a plugin that does what the median filter does, but also preserves peaks? The median filter, even at a radius of 2, tends to flatten sharp peaks. > > Thanks, > Neil > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html Karsten [hidden email] -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Neil Fazel
On Friday 06 Sep 2013 00:12:38 you wrote:
> Does ImageJ have a plugin that does what the median filter does, but also > preserves peaks? The median filter, even at a radius of 2, tends to flatten > sharp peaks. Is there such a thing? The purpose of the medial filter is precisely to get rid of the extreme values. Maybe some adaptive filtering would work instead? E.g. find the gradients in the image and then do a weighted gaussian average, using as weightings the inverse of the gradients (so regions with few gradients get more averaged than those with lots? Cheers Gabriel -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
I don't know what the image data in question is from the original posting
and therefore I might be totally of. For me it sound like Anisotropic diffusion filtering might be interesting for you. This filtering is aimed at noise reduction but also preserving image features at the same time. Again I might be totally of in my interpretation of the original question. Cheers Robert Gesendet: Freitag, 06. September 2013 um 10:57 Uhr Von: "Gabriel Landini" <[hidden email]> An: [hidden email] Betreff: Re: median filter that preserves peaks On Friday 06 Sep 2013 00:12:38 you wrote: > Does ImageJ have a plugin that does what the median filter does, but also > preserves peaks? The median filter, even at a radius of 2, tends to flatten > sharp peaks. Is there such a thing? The purpose of the medial filter is precisely to get rid of the extreme values. Maybe some adaptive filtering would work instead? E.g. find the gradients in the image and then do a weighted gaussian average, using as weightings the inverse of the gradients (so regions with few gradients get more averaged than those with lots? Cheers Gabriel -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Neil Fazel
Neil,
A median filter will remove sharp peaks. An easy modification is to test the home pixel against the neighborhood median using some criterion such as "must be greater than 2x the neighborhood median" before replacing the pixel value. You can tune the test so that the filter only replaces pixels that fit your needs. I don't know if there is a plugin that does this. Regards, John D.
|
In reply to this post by Neil Fazel
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 (15K) Download Attachment |
Hi Neil,
I guess you could always try a bandpass FFT filter. It's a bit more complicated than a median filter but once you managed all the tweaking you can get very good results. *Gabriel Lapointe, M.Sc.* Lab Manager / Microscopy Specialist Concordia University, Biology Department 7141 Sherbrooke St. West SP 534 Montréal QC H4B 1R6 Canada Lab : (514) 848-2424 x5988 Office : (514) 848-2424 x3008 Fax : (514) 848-2881 Cell : (514) 278-0247 [hidden email] cmac.concordia.ca http://gabriellapointe.ca 2013/9/6 Neil Fazel <[hidden email]> > 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 > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Neil Fazel
Dear Neil,
From a purely signal processing perspective, I suggest you use Fourier- (or better off wavelet-) denoising on such signals. They definitely should preserve your signal dynamics. A good illustration in 1D is given over here (http://www.mathworks.fr/products/demos/shipping/bioinfo/mspreprodemo.html#22) Alexandre --- Alexandre Dufour, Ph.D. Institut Pasteur - Quantitative Image Analysis Group 25, rue du Docteur Roux, Paris, France Research: http://www.bioimageanalysis.org/dufour Software: http://www.bioimageanalysis.org/icy On Sep 6, 2013, at 11:18 PM, 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 |
In reply to this post by Neil Fazel
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 |
In reply to this post by Neil Fazel
Ok, now I understand better.
What about applying top-hat filter with adequate size? Tophat means opening your image by a radius say 25 px and take the difference to the original. Threshold this difference and e.g. mask with it your original … This is a non-linear approach like median in comparison to the other recommendations! Regards Karsten Am 06.09.2013 um 23:18 schrieb Neil Fazel <[hidden email]>: > 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> Karsten [hidden email] -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Kenneth Sloan-2
On Saturday 07 Sep 2013 06:19:18 Kenneth Sloan wrote:
> 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. Very interesting. I guess that this would be similar to: 1. compute the local minima and maxima for a kernel size and their grey values, 2. filter the original image with a median filter 3. replace, in the filtered image, the local minima and maxima of the original. This macro implements that: //------------------8<--------------- // MedianLocalMinMax.txt // Based on the original idea of Kenneth Sloan // posted to the IJ mailing list on Sept 7, 2013. // G. Landini at bham. ac. uk a=getNumber("Local radius",3); setBatchMode(true); b=getTitle(); setOption("BlackBackground", true); run("Duplicate...", "title=Median"); run("Duplicate...", "title=Maxima"); run("Maximum...", "radius="+a); run("Image Calculator...", "image1=Maxima operation=Subtract image2=Median create"); setThreshold(0, 0); run("Convert to Mask"); selectWindow("Maxima"); run("Close"); selectWindow("Result of Maxima"); rename("LocalMaxima"); selectWindow("Median"); run("Duplicate...", "title=Minima"); run("Minimum...", "radius="+a); run("Image Calculator...", "image1=Median operation=Subtract image2=Minima create"); setThreshold(0, 0); run("Convert to Mask"); selectWindow("Minima"); run("Close"); selectWindow("Result of Median"); rename("LocalMinima"); imageCalculator("Add" , "LocalMaxima","LocalMinima"); selectWindow("LocalMinima"); close(); selectWindow("Median"); run("Median...", "radius="+a); imageCalculator("Subtract", "Median","LocalMaxima"); imageCalculator("AND", "LocalMaxima", b); imageCalculator("Add", "Median","LocalMaxima"); selectWindow("LocalMaxima"); close(); selectWindow("Median"); rename("MedianLocalMinMax"); setBatchMode(false); //------------------8<--------------- Furthermore, it is also possible to replace with the *regional* minima and maxima instead, as those are regions guaranteed to be surrounded by brighter and darker pixels respectively and more likely to be peaks and wells in the image. Interestingly the regional minima and maxima do not depend on kernel sizes. The following macro does that (the Domes plugin is part of the morphology collection, available in my page) //------------------8<--------------- // MedianRegionalMinMax.txt // Based on the original idea of Kenneth Sloan // posted to the IJ mailing list on Sept 7, 2013. // G. Landini at bham. ac. uk a=getNumber("Local radius",3); setBatchMode(true); b=getTitle(); setOption("BlackBackground", true); run("Duplicate...", "title=Median"); run("Duplicate...", "title=RMaxima"); run("Domes ", "height=1"); setThreshold(1, 255); run("Convert to Mask"); selectWindow("Median"); run("Duplicate...", "title=RMinima"); run("Domes ", "height=1 basins"); setThreshold(1, 255); run("Convert to Mask"); imageCalculator("Add" , "RMaxima","RMinima"); selectWindow("RMinima"); close(); selectWindow("Median"); run("Median...", "radius="+a); imageCalculator("Subtract", "Median","RMaxima"); imageCalculator("AND", "RMaxima", b); imageCalculator("Add", "Median","RMaxima"); selectWindow("RMaxima"); close(); selectWindow("Median"); rename("MedianRegionalMinMax"); setBatchMode(false); //------------------8<--------------- Hope it is useful. Let me know of any bugs. Cheers Gabriel -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Just so.
More generally (I guess): a) produce a boolean mask identifying "good pixels" and "pixels in need of correction" b) replace all the "pixels in need of correction" by a value computed from the "good pixels" Again (I really think this is a point worth emphasizing) - this is the kind of freedom you have (use it, or abuse it) when you give up the idea that you are *only* doing linear signal processing, or that the proper definition of "what you are doing" is best stated in terms of the Fourier Domain. Just, please note the "abuse it" clause. Not everything that is possible is a good idea! for example…one reason that people like Median instead of Mean is that Median *tends* to completely discount outliers, while Mean can be significantly affected by certain types of noise. The Median computed from the "good pixels" is not terribly different than the Median of all the pixels (but the Mean might be). If you implement the idea of a mask to identify the pixels that need to be changed AND the ones to NOT use in the computation, you can get this effect with nearly any filter. The only rub is that it's not linear anymore. To compensate you, note that you might get away with doing the filtering IN-PLACE (since you only change pixels that do not participate in the computation!) I think someone might have a lot of fun with this idea. Please steal it, and let me know if it gains any traction. -- Kenneth Sloan [hidden email] On Sep 7, 2013, at 12:04 , Gabriel Landini <[hidden email]> wrote: > On Saturday 07 Sep 2013 06:19:18 Kenneth Sloan wrote: >> 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. > > Very interesting. I guess that this would be similar to: > 1. compute the local minima and maxima for a kernel size and their grey > values, > 2. filter the original image with a median filter > 3. replace, in the filtered image, the local minima and maxima of the > original. > > This macro implements that: > //------------------8<--------------- > // MedianLocalMinMax.txt > // Based on the original idea of Kenneth Sloan > // posted to the IJ mailing list on Sept 7, 2013. > // G. Landini at bham. ac. uk > > a=getNumber("Local radius",3); > setBatchMode(true); > b=getTitle(); > setOption("BlackBackground", true); > run("Duplicate...", "title=Median"); > run("Duplicate...", "title=Maxima"); > run("Maximum...", "radius="+a); > run("Image Calculator...", "image1=Maxima operation=Subtract image2=Median > create"); > setThreshold(0, 0); > run("Convert to Mask"); > selectWindow("Maxima"); > run("Close"); > selectWindow("Result of Maxima"); > rename("LocalMaxima"); > > selectWindow("Median"); > run("Duplicate...", "title=Minima"); > run("Minimum...", "radius="+a); > run("Image Calculator...", "image1=Median operation=Subtract image2=Minima > create"); > setThreshold(0, 0); > run("Convert to Mask"); > selectWindow("Minima"); > run("Close"); > selectWindow("Result of Median"); > rename("LocalMinima"); > > imageCalculator("Add" , "LocalMaxima","LocalMinima"); > selectWindow("LocalMinima"); > close(); > > selectWindow("Median"); > run("Median...", "radius="+a); > imageCalculator("Subtract", "Median","LocalMaxima"); > imageCalculator("AND", "LocalMaxima", b); > imageCalculator("Add", "Median","LocalMaxima"); > > selectWindow("LocalMaxima"); > close(); > > selectWindow("Median"); > rename("MedianLocalMinMax"); > > setBatchMode(false); > //------------------8<--------------- > > > Furthermore, it is also possible to replace with the *regional* minima and > maxima instead, as those are regions guaranteed to be surrounded by brighter > and darker pixels respectively and more likely to be peaks and wells in the > image. > Interestingly the regional minima and maxima do not depend on kernel sizes. > > The following macro does that (the Domes plugin is part of the morphology > collection, available in my page) > > //------------------8<--------------- > // MedianRegionalMinMax.txt > // Based on the original idea of Kenneth Sloan > // posted to the IJ mailing list on Sept 7, 2013. > // G. Landini at bham. ac. uk > > a=getNumber("Local radius",3); > setBatchMode(true); > b=getTitle(); > setOption("BlackBackground", true); > run("Duplicate...", "title=Median"); > run("Duplicate...", "title=RMaxima"); > run("Domes ", "height=1"); > setThreshold(1, 255); > run("Convert to Mask"); > > selectWindow("Median"); > run("Duplicate...", "title=RMinima"); > run("Domes ", "height=1 basins"); > setThreshold(1, 255); > run("Convert to Mask"); > > imageCalculator("Add" , "RMaxima","RMinima"); > selectWindow("RMinima"); > close(); > > selectWindow("Median"); > run("Median...", "radius="+a); > imageCalculator("Subtract", "Median","RMaxima"); > imageCalculator("AND", "RMaxima", b); > imageCalculator("Add", "Median","RMaxima"); > > selectWindow("RMaxima"); > close(); > > selectWindow("Median"); > rename("MedianRegionalMinMax"); > > setBatchMode(false); > //------------------8<--------------- > > > Hope it is useful. Let me know of any bugs. > Cheers > > Gabriel > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Neil Fazel
Hi Alexandre,
Thank you for the tips. I decided to give wavelet filtering a try and downloaded the ImageJplugin Haar Wavelet Filter (http://imagej.nih.gov/ij/plugins/haar-wavelet-filter.html). After converting the original 32-bit image to 8-bit image (as required by the filter) and running the filter using default parameters, I got a Java out of bounds error: ImageJ 1.47s; Java 1.6.0_51 [32-bit]; Mac OS X 10.6.8; 25MB of 1500MB (1%) java.lang.ArrayIndexOutOfBoundsException: 275 at Haar_wavelet_filter.Haar_1d(Haar_wavelet_filter.java:382) <snip> I'll try to debug this; but based on the pictures on the Mathworks page you sent, wavelet filtering is worth pursuing. Regards, Neil -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Neil Fazel
> I don't know what the image data in question is from the original posting
Robert, the image I posted was a vertical profile plot of x-rays filtered by Al and Cu filter packs and recorded on an imaging plate. Thanks, Neil -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Neil Fazel
Thanks for the responses.
It seems to me that a generalized spatial filter (e.g. the "XXXFilter" suggested by Kenneth) might be the way to go. I did give FFT a try and, after tweaking the parameters, got results matching what the median filter produced. However, it seems to me that one needs to be careful with FFT filtering. Sometimes high frequency components of the signal are noise and need to be removed. Sometimes they are actual signal and removing them biases the data. In such cases, a spatial filter such as mean or median may be appropriate. For example, in my case, I have x-ray which is filtered by Cu or Al and recorded on an imaging plate. What looks like noise could in fact be from sideways scattering of x-rays inside the filter pack. One needs to determine whether such signal should be removed (via FFT filter) or merely smoothed (via mean or median filter) to make analysis easier. Regards, Neil -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Neil,
There have been a lot of good suggestions in this thread but it seems from your post that you are not quite where you want to be. So here is one more idea to try. Perhaps a CFAR (constant false alarm ratio) filter might help pick the real target peaks that need to be preserved out of the noise. 2D CFAR is relatively easy to code and may be worth a try by itself or in combination with other techniques. Regards, John D.
|
Free forum by Nabble | Edit this page |