Can anybody help me debug my plugin?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Can anybody help me debug my plugin?

junsheng
 
Hello,

I want to do the z direction median filter to generate a median value in
different slice for background substraction. I have some problem in
debug the following plugin. Can anybody help me with it.

Thank you very much.

Best wishes,
Junsheng Wang

public class Z_Direction_Median_Filter implements PlugInFilter{
   
      int m = stack.getWidth();
        int n = stack.getHeight();
        int dimension = m*n;
        int nSlices = stack.getSize();
      public double[] zPixels;
      public double[] xyPixels;
      public double zMedian = 0;      
public void run() {
        if (nSlices==1)
       exit("Stack required");
  for (j=1; j<=dimension; j++)
   for (i=1; i<=nSlices; i++) {
       setSlice(i);
       zPixels[i]=(double)stack.getPixels(i);
   }
       zMedian=median(zPixels);
         xyPixels[j]=zMedian;
  }    
  run("Duplicate...", "title=zMedian");
  run("Select All");    
  setColor(xyPixels);
  run("Fill");
}
private static double median(double array[]){
        Arrays.sort(array);
        int len = array.length;
        if(len%2==0)return((array[(len/2)-1]+array[len/2])/2);
        else return array[((len-1)/2)];
    }  
}
Reply | Threaded
Open this post in threaded view
|

Re: Can anybody help me debug my plugin?

dscho
Hi,

> public class Z_Direction_Median_Filter implements PlugInFilter{
>    
>       int m = stack.getWidth();

There is no member stack. You have to define it first (probably in the
setup() or run() method. After that, you can initialize m, but not before.

> public void run() {

The method run() gets passed one parameter of type ImageProcessor.

>   for (j=1; j<=dimension; j++)
>    for (i=1; i<=nSlices; i++) {
>        setSlice(i);

This is inefficient. You might want to initialize a member of type
double[][] to the value returned by (double[])stack.getPixels().

>   run("Duplicate...", "title=zMedian");
>   run("Select All");    
>   setColor(xyPixels);
>   run("Fill");
> }

What is this? Seems you got something mixed up here.

Hth,
Dscho