Hi,
After I changed from ImageJ version 1.45i to 1.45j I experienced problems with the median filters (and minimum, maximum filters as well) in some of my plugins. As an example, see the plugin below with a method to smooth a stack with a median filter. The result is a totally black stack. I have tried many things like updating the ImagePlus, duplicating the ImageProcessor before the filtering but nothing worked. In the end I worked around it by using this command: IJ.run(imp, "Median...", "radius=2 slice"). So, I am not sure whether this is a bug or we just have to work around it. I suspect it has something to do with a new implementation of filtering as stated in the release notes: " Thanks to Michael Schmid, the Median, Mean, Minimum, Maximum and Variance filters use less memory when processing non-float images." Thanks for any help! Leonard Bosgraaf public class test_smoothStack implements PlugIn { public void run(String arg) { long time1= System.currentTimeMillis(); ImagePlus img = WindowManager.getCurrentImage(); smoothStack( img, 1.1213, "median" ); long time2= System.currentTimeMillis(); IJ.log("time to run= "+ (time2- time1) ); IJ.log("done"); } ////------------------------------------- END RUN -------------------------------------------------------------------- //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX // Method to perform a smoothing (mean or median of surrounding pixels) on a stack. // The strength of the smoothing (radius) must be passed. public void smoothStack( ImagePlus img, double smoothRadius, String method) { int mode= 0; ImageStack stack= img.getStack(); ImageProcessor ip; RankFilters RF= new RankFilters(); if ( method== "median") { mode= 4; } else if (method== "mean") { mode= 0; } else { IJ.log("error in smoothStack method; choosing 'mean' as mode and continuing"); } for (int slice= 1; slice<= stack.getSize(); slice++) { // for all slices ip = stack.getProcessor(slice); RF.rank( ip, smoothRadius, mode); // perform filter with mean or median, with radius smoothRadius } img.setStack(null, stack); // update img } } |
On Jun 30, 2011, at 6:17 AM, Xalt wrote:
> Hi, > > After I changed from ImageJ version 1.45i to 1.45j I experienced problems > with the median filters (and minimum, maximum filters as well) in some of my > plugins. As an example, see the plugin below with a method to smooth a stack > with a median filter. The result is a totally black stack. I have tried many > things like updating the ImagePlus, duplicating the ImageProcessor before > the filtering but nothing worked. In the end I worked around it by using > this command: IJ.run(imp, "Median...", "radius=2 slice"). So, I am not sure > whether this is a bug or we just have to work around it. I suspect it has > something to do with a new implementation of filtering as stated in the > release notes: " Thanks to Michael Schmid, the Median, Mean, Minimum, > Maximum and Variance filters use less memory when processing non-float > images." This bug is fixed in the ImageJ 1.45k daily build. -wayne > public class test_smoothStack implements PlugIn { > public void run(String arg) { > long time1= System.currentTimeMillis(); > ImagePlus img = WindowManager.getCurrentImage(); > > smoothStack( img, 1.1213, "median" ); > > long time2= System.currentTimeMillis(); > IJ.log("time to run= "+ (time2- time1) ); > > IJ.log("done"); > > > } ////------------------------------------- END RUN > -------------------------------------------------------------------- > > > //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX > // Method to perform a smoothing (mean or median of surrounding pixels) on > a stack. > // The strength of the smoothing (radius) must be passed. > public void smoothStack( ImagePlus img, double smoothRadius, String method) > { > int mode= 0; > ImageStack stack= img.getStack(); > ImageProcessor ip; > RankFilters RF= new RankFilters(); > if ( method== "median") { > mode= 4; > } else if (method== "mean") { > mode= 0; > } else { > IJ.log("error in smoothStack method; choosing 'mean' as mode and > continuing"); > } > > for (int slice= 1; slice<= stack.getSize(); slice++) { // for all slices > ip = stack.getProcessor(slice); > RF.rank( ip, smoothRadius, mode); // perform filter with mean or median, > with radius smoothRadius > } > img.setStack(null, stack); // update img > } > > } > > -- > View this message in context: http://imagej.588099.n2.nabble.com/Problem-with-median-filter-in-version-1-45j-tp6532622p6532622.html > Sent from the ImageJ mailing list archive at Nabble.com. |
Free forum by Nabble | Edit this page |