new version of Fast Filters plugin

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

new version of Fast Filters plugin

Michael Schmid
Hi everyone,

in case you are interested: I have updated my Fast Filters plugin.
It provides mean, minimum, maximum, "pseudo-median", top-hat and  
background subtraction filters with a rectangular n*m kernel (in  
contrast to the ImageJ built-in Process>Filters, which use a circular  
kernel).

Improvements:
- Parallel threads for multiprocessor machines (except for conversion  
from/to float, thus the speed gain is largest for float images).
- Float images may contain NaN (not a number) pixels.

http://imagejdocu.tudor.lu/doku.php?id=plugin:filter:fast_filters:start

Michael
Reply | Threaded
Open this post in threaded view
|

Re: new version of Fast Filters plugin

justelouise
Hi,

I've tried using the plugin in my own java program. However, the results are different compared to output when using the ImageJ software. Any ideas?

Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: new version of Fast Filters plugin

Michael Schmid
Hi anonymous? Louise?,

if you want to use a PlugInFilter or ExtendedPlugInFilter in your own plugin or program, you have a two possibilities:

(1) With ImageJ, use it via IJ.run(imp, "Fast_Filters", "options...");
You get the command with Plugins>Macros>Record in 'Java' mode

(2) See whether there is a public method that you can use. The Fast Filters plugin offers a method
  filterFloat(ImageProcessor ip, int type, int radius, boolean xDirection,
            int extraX, int extraY, int maxThreads)
For this, you have to convert the image to a FloatProcessor if it isn't one
  ImageProcessor.toFloat(int channelNumber, FloatProcessor fp);
convert it back after processing, and care that the ImageProcessor has the correct selection. Also, it will do only elementary steps; you will have to call it for each direction (x&y) and additionally call it again with different 'type' for actions like "eliminate maxima" (first MIN, then MAX).

In principle, you could also write your own program that does essentially the same as the PlugInFilterRunner of ImageJ, i.e., calling the PlugInFilter's setup, showDialog, and run(ip); methods; and do everything that is demanded by the flags returned by the setup and showDialog methods. But that's a rather nasty hack, and difficult to get it right.

Michael
________________________________________________________________
On Jun 15, 2015, at 13:19, justelouise wrote:

> Hi,
>
> I've tried using the plugin in my own java program. However, the results are
> different compared to output when using the ImageJ software. Any ideas?
>
> Thanks!

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: new version of Fast Filters plugin

justelouise
Does that mean I could just directly call the filterFloat method? What I'm doing right now is that I'm calling the run method and just defining the parameters I've used through ImageJ.
Reply | Threaded
Open this post in threaded view
|

Re: new version of Fast Filters plugin

Michael Schmid
Hi Louise (?),

as I said, you can simply call
  IJ.run(imp, "Fast_Filters", "filter=minimum x=10 y=10 preprocessing=none offset=0");
and it would do exactly the same as if you run it manually.

Otherwise you can use (for floating point images) e.g.
  ImageProcessor ip = imp.getProcessor();
  int radius = 10;
  int maxThreads = Runtime.getRuntime().availableProcessors();
  filterFloat(ip, /*type=*/3, radius, /*xDirection=*/true,
            /*extraX=*/0, /*extraY=*/radius, /*maxThreads=*/2);
  filterFloat(ip, /*type=*/3, radius, /*xDirection=*/false,
            /*extraX=*/0, /*extraY=*/0, maxThreads);

So you see, using the filterFloat method is much more cumbersome, and this does not include conversion from/to float yet and does not process all slices of a stack if desired. It will be even worse if you want to subtract the result or you need a 'composite' action such as "eliminate maxima" or "background from maxima".

So for sure, it is much easier to use IJ.run. You can also have variable parameters in it, e.g.

  int radius = 10;
  IJ.run(imp, "Fast_Filters", "filter=minimum x="+radius+" y="+radius+" preprocessing=none offset=0");

By the way, for proper use of the filterFloat method, the constants for 'type' such as MEAN, MIN, MAX should be defined as public in the FastFilters plugin. Seems that I have forgotten to do this; if I find time, I'll correct it.

Michael
________________________________________________________________
On Jun 16, 2015, at 16:01, justelouise wrote:

> Does that mean I could just directly call the filterFloat method? What I'm
> doing right now is that I'm calling the run method and just defining the
> parameters I've used through ImageJ.
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/new-version-of-Fast-Filters-plugin-tp3684966p5013181.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: new version of Fast Filters plugin

justelouise
Then I have to register first the plugin into ImageJ, right?

BUT. What I'm doing with other plugins is just copying the .java file into my project then tweak it according to my needs then just call the run method. That's how I'm using the Fast_Filters plugin. But, I still wasn't able to get the output I had when using ImageJ. Is ImageJ doing something else to the image before running it with the fast filters plugin?

I'm sorry if I keep on asking question. I was just really wondering as to why the results are different evn though the way I'm calling the plugin seems to be working.
Reply | Threaded
Open this post in threaded view
|

Re: new version of Fast Filters plugin

Michael Schmid
Hi Louise (?)

for IJ.run, the plugin must appear somewhere in the ImageJ menus. If you create your own collection of plugins as a .jar file (or just a .zip file with the class files will also do), have a plugins.config file and specify it there.

See, e.g.
  http://rsbweb.nih.gov/ij/plugins/jar-demo.html
  http://imagejdocu.tudor.lu/doku.php?id=howto:plugins:howto_create_an_imagej_plugin_jar_file

---

For the direct call to FastFilters.filterFloat, it is not enough if you say you wonder "why the results are different". You have to say (1) which operation you do (e.g. in the "run" format of the macro recorder) and (2) how the result differs.

There are several things that ImageJ does before and after running a PlugInFilter:

- Converting to float and back (separately for R, G, B of RGB images) because of the CONVERT_TO_FLOAT flag
- roi.endPaste() if there is a Roi (finishing previous paste operations)
- For area Rois, transferring the Roi from the ImagePlus to the ImageProcessor
- Creating a snapshot of the ImageProcessor (because of the SNAPSHOT flag)
- Reverting the pixels outside a non rectangular Roi to the original after calling the PluginFilter (because of the SUPPORTS_MASKING flag)


Michael
________________________________________________________________
On Jun 17, 2015, at 14:17, justelouise wrote:

> Then I have to register first the plugin into ImageJ, right?
>
> BUT. What I'm doing with other plugins is just copying the .java file into
> my project then tweak it according to my needs then just call the run
> method. That's how I'm using the Fast_Filters plugin. But, I still wasn't
> able to get the output I had when using ImageJ. Is ImageJ doing something
> else to the image before running it with the fast filters plugin?
>
> I'm sorry if I keep on asking question. I was just really wondering as to
> why the results are different evn though the way I'm calling the plugin
> seems to be working.
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/new-version-of-Fast-Filters-plugin-tp3684966p5013193.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: new version of Fast Filters plugin

justelouise
I'm having a hard time creating a jar file for the plugin. I'm getting an error.

Anyway, may I know the step by step processing ImageJ does before and after running the filter? I'll just try to simulate that.

I just want to make this plugin work as it is when I tried it in ImageJ.

Thank you so much for all your help!
Reply | Threaded
Open this post in threaded view
|

Re: new version of Fast Filters plugin

Michael Schmid
On Sat, June 20, 2015 08:39, justelouise wrote:
> Anyway, may I know the step by step processing ImageJ does before and
> after running the filter? I'll just try to simulate that.

For (Extended)PlugInFilters, the processing is done in PlugInFilterRunner.
You can find the code at
  https://github.com/imagej/imagej1/blob/master/ij/plugin/filter/PlugInFilterRunner.java

It's quite a bit of code, but you can ignore all those code parts that are
for flags that the PlugInFilter under consideration does not use.

For the Fast_Filters, if you don't populate the variables for the filter
parameters from the dialog, so you can use its run(ip) method, you also
have to code an equivalent to its run(ip). Alternatively, of course you
can modify the Fast_Filters code and add a public method that fits your
needs.

Michael

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: new version of Fast Filters plugin

justelouise
Hi,

I was able to get the results I need when running the plugin through he PlugInFilterrunner. I wasn't able to replicate it even though I just copy-pasted the PlugInFilterRunner implementation. The problem now is that the dialog box is showing for the fast filters plugin.

Anyway, thank you so much for all your help. This is a big step for me in image processing. Kudos!
Reply | Threaded
Open this post in threaded view
|

Re: new version of Fast Filters plugin

Michael Schmid
On Jun 21, 2015, at 11:16, justelouise wrote:
> I was able to get the results I need when running the plugin through he
> PlugInFilterrunner. I wasn't able to replicate it even though I just
> copy-pasted the PlugInFilterRunner implementation. The problem now is that
> the dialog box is showing for the fast filters plugin.

The dialog options are automatically filled in if you set Macro.setOptions(options) and the thread has a name starting with "Run$_". For an appropriate code, see

  https://github.com/imagej/imagej1/blob/master/ij/IJ.java#l257

But as I wrote previously, it would be much easier to have the Fast Filters somewhere in the menu and then simply call
  IJ.run(imp, "Fast Filters", options).
You even don't need to build a proper .jar; just create a .zip with all the class files you need and the plugins.config, have an underscore character in the filename, and place it into ImageJ/plugins or an immediate subfolder thereof.

Michael

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: new version of Fast Filters plugin

ctrueden
Hi Michael,

> You even don't need to build a proper .jar; just create a .zip with
> all the class files you need and the plugins.config, have an
> underscore character in the filename, and place it into ImageJ/plugins
> or an immediate subfolder thereof.

This is an error prone process, and the ImageJ team cannot guarantee it
will still work in the future.

Much better to use File > Export as .jar from the Script Editor. Or package
the JAR file using other standard means such as File > Export > JAR file
from Eclipse. (Every IDE has a feature like this.)

Regards,
Curtis

On Mon, Jun 22, 2015 at 2:38 AM, Michael Schmid <[hidden email]>
wrote:

> On Jun 21, 2015, at 11:16, justelouise wrote:
> > I was able to get the results I need when running the plugin through he
> > PlugInFilterrunner. I wasn't able to replicate it even though I just
> > copy-pasted the PlugInFilterRunner implementation. The problem now is
> that
> > the dialog box is showing for the fast filters plugin.
>
> The dialog options are automatically filled in if you set
> Macro.setOptions(options) and the thread has a name starting with "Run$_".
> For an appropriate code, see
>
>   https://github.com/imagej/imagej1/blob/master/ij/IJ.java#l257
>
> But as I wrote previously, it would be much easier to have the Fast
> Filters somewhere in the menu and then simply call
>   IJ.run(imp, "Fast Filters", options).
> You even don't need to build a proper .jar; just create a .zip with all
> the class files you need and the plugins.config, have an underscore
> character in the filename, and place it into ImageJ/plugins or an immediate
> subfolder thereof.
>
> Michael
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: new version of Fast Filters plugin

justelouise
In reply to this post by Michael Schmid
Hi Michael,

I was kinda wondering if you could help me out with the usage of the Fast filters plugin. I am trying to incorporate this in my application but not getting the desired output I got when tied it in ImageJ.

My email address is louiseann.apostol@gmail.com. Please send me an email to that address if possible. I badly need your help.

Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: new version of Fast Filters plugin

justelouise
Hi,

I've been trying, for months, to make the fast filters plugin works according to my needs but no luck. I rewrote it a little to become more pretty straightforward when calling it (see attached file). Before calling the top hat transform, I first convert the image to a float processor then get snapshot. However, the output image I get is different from that when I tried the plugin with ImageJ standalone application. Any ideas?

TopHat.java