Login  Register

Problem with median filter in version 1.45j

Posted by Xalt on Jun 30, 2011; 10:17am
URL: http://imagej.273.s1.nabble.com/Problem-with-median-filter-in-version-1-45j-tp3684048.html

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
 }
 
}