Use Rank() - rankFloat() (RankFilters) in a plugin.

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

Use Rank() - rankFloat() (RankFilters) in a plugin.

Joris FA Meys
Dear all,

I'm writing (yet another) plugin for edge detection, and i want to apply the
median filter, but not with a 3x3 kernel but with a circular mask. I know I
can run the command with IJ.doCommand("Median"), but when I try that (or
IJ.run), I get the message "image locked". with IJ.RunPlugIn("Median",null),
I get simply nothing.

Plus, I don't want the image filter to open, I just want to apply the method
rankFloat to my imageprocessor with a fixed radius. I tried accessing the
method, but got (off course) the static/nonstatic error. Tried to instantize
RankFilters and do it that way, but that didn't want to work either. Right
now, I copied the code of rankFloat() and adjusted it for my own use. It
works, but it's not really elegant to say at least.

Anybody who knows to do this right?
Kind regards
Joris
Reply | Threaded
Open this post in threaded view
|

Re: Use Rank() - rankFloat() (RankFilters) in a plugin.

Joris FA Meys
Thank you very much. Tried it, but I seem not to be able to get it run on
the right image. it should run on the image processor ip2 in the code, but
it destructively changes the first slice in the original stack. Any way of
getting around that one?

Kind regards
Joris

Code :
public static ImageProcessor getDeriche(ImageProcessor ip, float alpha,
double radius){
        int type = getType(ip);
        if (type==OTHER){
            IJ.showMessage("Deriche works only on greyscale or pseudocolored
images");
            return null;
        }
        ArrayList<double[]> arrays = null;
        ImageProcessor ip2= ip.duplicate();
        //if (radius > 0)ip2 = applyMedian(ip2, radius); // to the function
I copied from rankFloat.
        if (radius>0)IJ.run("Median...","radius="+radius);

        arrays = dericheCalc(ip2,alpha); // self-defined function
        double[] norm = arrays.get(0);
        double[] angle = arrays.get(1);
        FloatProcessor normfp = new FloatProcessor(ip2.getWidth(),
ip2.getHeight(), norm);
        normfp.resetMinAndMax();
        FloatProcessor anglefp = new FloatProcessor(ip2.getWidth(),
ip2.getHeight(), angle);
        anglefp.resetMinAndMax();
        ip2 = nonMaximalSuppression(normfp, anglefp);
        return ip2;
    }



On Thu, Feb 5, 2009 at 3:53 PM, Wayne Rasband <[hidden email]> wrote:

> Dear Joris,
>
> On Feb 5, 2009, at 6:48 AM, joris meys wrote:
>
>  Dear all,
>>
>> I'm writing (yet another) plugin for edge detection, and i want to apply
>> the
>> median filter, but not with a 3x3 kernel but with a circular mask. I know
>> I
>> can run the command with IJ.doCommand("Median"), but when I try that (or
>> IJ.run), I get the message "image locked". with
>> IJ.RunPlugIn("Median",null),
>> I get simply nothing.
>>
>
> You can avoid the "image locked" error by changing your plugin so that it
> implements the PlugIn interface instead of PlugInFiler and run the median
> filter using
>
>    run("Median...", "radius=1");
>
> -wayne
>
>
>
>> Plus, I don't want the image filter to open, I just want to apply the
>> method
>> rankFloat to my imageprocessor with a fixed radius. I tried accessing the
>> method, but got (off course) the static/nonstatic error. Tried to
>> instantize
>> RankFilters and do it that way, but that didn't want to work either. Right
>> now, I copied the code of rankFloat() and adjusted it for my own use. It
>> works, but it's not really elegant to say at least.
>>
>> Anybody who knows to do this right?
>> Kind regards
>> Joris
>>
>>
>
Reply | Threaded
Open this post in threaded view
|

Re: Use Rank() - rankFloat() (RankFilters) in a plugin.

Wayne Rasband
On Feb 5, 2009, at 10:37 AM, joris meys wrote:

> Thank you very much. Tried it, but I seem not to be able to get it run
> on
> the right image. it should run on the image processor ip2 in the code,
> but
> it destructively changes the first slice in the original stack. Any
> way of
> getting around that one?

  IJ.run("Median...","radius="+radius) runs on the current slice of the
current stack. You can call the rank() method of the RankFilters class
to median filter an ImageProcessor. Here is a JavaScript example:

   importClass(Packages.ij.plugin.filter.RankFilters)
   img = IJ.getImage();
   ip = img.getProcessor();
   filter = new RankFilters();
   radius = 3;
   filter.rank(ip, radius, RankFilters.MEDIAN);
   img.updateAndDraw();
   IJ.showProgress(1);

-wayne


>
> Kind regards
> Joris
>
> Code :
> public static ImageProcessor getDeriche(ImageProcessor ip, float alpha,
> double radius){
>         int type = getType(ip);
>         if (type==OTHER){
>             IJ.showMessage("Deriche works only on greyscale or
> pseudocolored
> images");
>             return null;
>         }
>         ArrayList<double[]> arrays = null;
>         ImageProcessor ip2= ip.duplicate();
>         //if (radius > 0)ip2 = applyMedian(ip2, radius); // to the
> function
> I copied from rankFloat.
>         if (radius>0)IJ.run("Median...","radius="+radius);
>
>         arrays = dericheCalc(ip2,alpha); // self-defined function
>         double[] norm = arrays.get(0);
>         double[] angle = arrays.get(1);
>         FloatProcessor normfp = new FloatProcessor(ip2.getWidth(),
> ip2.getHeight(), norm);
>         normfp.resetMinAndMax();
>         FloatProcessor anglefp = new FloatProcessor(ip2.getWidth(),
> ip2.getHeight(), angle);
>         anglefp.resetMinAndMax();
>         ip2 = nonMaximalSuppression(normfp, anglefp);
>         return ip2;
>     }
>
>
>
> On Thu, Feb 5, 2009 at 3:53 PM, Wayne Rasband <[hidden email]> wrote:
>
>> Dear Joris,
>>
>> On Feb 5, 2009, at 6:48 AM, joris meys wrote:
>>
>>  Dear all,
>>>
>>> I'm writing (yet another) plugin for edge detection, and i want to
>>> apply
>>> the
>>> median filter, but not with a 3x3 kernel but with a circular mask. I
>>> know
>>> I
>>> can run the command with IJ.doCommand("Median"), but when I try that
>>> (or
>>> IJ.run), I get the message "image locked". with
>>> IJ.RunPlugIn("Median",null),
>>> I get simply nothing.
>>>
>>
>> You can avoid the "image locked" error by changing your plugin so
>> that it
>> implements the PlugIn interface instead of PlugInFiler and run the
>> median
>> filter using
>>
>>    run("Median...", "radius=1");
>>
>> -wayne
>>
>>
>>
>>> Plus, I don't want the image filter to open, I just want to apply the
>>> method
>>> rankFloat to my imageprocessor with a fixed radius. I tried
>>> accessing the
>>> method, but got (off course) the static/nonstatic error. Tried to
>>> instantize
>>> RankFilters and do it that way, but that didn't want to work either.
>>> Right
>>> now, I copied the code of rankFloat() and adjusted it for my own
>>> use. It
>>> works, but it's not really elegant to say at least.
>>>
>>> Anybody who knows to do this right?
>>> Kind regards
>>> Joris
>>>
>>>
>>
>
Reply | Threaded
Open this post in threaded view
|

Re: Use Rank() - rankFloat() (RankFilters) in a plugin.

Joris FA Meys
That was what I was looking for. Thank you very much!
Kind regards
Joris

On Thu, Feb 5, 2009 at 6:34 PM, Wayne Rasband <[hidden email]> wrote:

> On Feb 5, 2009, at 10:37 AM, joris meys wrote:
>
>  Thank you very much. Tried it, but I seem not to be able to get it run on
>> the right image. it should run on the image processor ip2 in the code, but
>> it destructively changes the first slice in the original stack. Any way of
>> getting around that one?
>>
>
>  IJ.run("Median...","radius="+radius) runs on the current slice of the
> current stack. You can call the rank() method of the RankFilters class to
> median filter an ImageProcessor. Here is a JavaScript example:
>
>  importClass(Packages.ij.plugin.filter.RankFilters)
>  img = IJ.getImage();
>  ip = img.getProcessor();
>  filter = new RankFilters();
>  radius = 3;
>  filter.rank(ip, radius, RankFilters.MEDIAN);
>  img.updateAndDraw();
>  IJ.showProgress(1);
>
> -wayne
>
>
>
>
>> Kind regards
>> Joris
>>
>> Code :
>> public static ImageProcessor getDeriche(ImageProcessor ip, float alpha,
>> double radius){
>>        int type = getType(ip);
>>        if (type==OTHER){
>>            IJ.showMessage("Deriche works only on greyscale or
>> pseudocolored
>> images");
>>            return null;
>>        }
>>        ArrayList<double[]> arrays = null;
>>        ImageProcessor ip2= ip.duplicate();
>>        //if (radius > 0)ip2 = applyMedian(ip2, radius); // to the function
>> I copied from rankFloat.
>>        if (radius>0)IJ.run("Median...","radius="+radius);
>>
>>        arrays = dericheCalc(ip2,alpha); // self-defined function
>>        double[] norm = arrays.get(0);
>>        double[] angle = arrays.get(1);
>>        FloatProcessor normfp = new FloatProcessor(ip2.getWidth(),
>> ip2.getHeight(), norm);
>>        normfp.resetMinAndMax();
>>        FloatProcessor anglefp = new FloatProcessor(ip2.getWidth(),
>> ip2.getHeight(), angle);
>>        anglefp.resetMinAndMax();
>>        ip2 = nonMaximalSuppression(normfp, anglefp);
>>        return ip2;
>>    }
>>
>>
>>
>> On Thu, Feb 5, 2009 at 3:53 PM, Wayne Rasband <[hidden email]> wrote:
>>
>>  Dear Joris,
>>>
>>> On Feb 5, 2009, at 6:48 AM, joris meys wrote:
>>>
>>>  Dear all,
>>>
>>>>
>>>> I'm writing (yet another) plugin for edge detection, and i want to apply
>>>> the
>>>> median filter, but not with a 3x3 kernel but with a circular mask. I
>>>> know
>>>> I
>>>> can run the command with IJ.doCommand("Median"), but when I try that (or
>>>> IJ.run), I get the message "image locked". with
>>>> IJ.RunPlugIn("Median",null),
>>>> I get simply nothing.
>>>>
>>>>
>>> You can avoid the "image locked" error by changing your plugin so that it
>>> implements the PlugIn interface instead of PlugInFiler and run the median
>>> filter using
>>>
>>>   run("Median...", "radius=1");
>>>
>>> -wayne
>>>
>>>
>>>
>>>  Plus, I don't want the image filter to open, I just want to apply the
>>>> method
>>>> rankFloat to my imageprocessor with a fixed radius. I tried accessing
>>>> the
>>>> method, but got (off course) the static/nonstatic error. Tried to
>>>> instantize
>>>> RankFilters and do it that way, but that didn't want to work either.
>>>> Right
>>>> now, I copied the code of rankFloat() and adjusted it for my own use. It
>>>> works, but it's not really elegant to say at least.
>>>>
>>>> Anybody who knows to do this right?
>>>> Kind regards
>>>> Joris
>>>>
>>>>
>>>>
>>>
>>