Unable to implement filters in Java

dependencies
imagej
eclipse
java

#1

I am using the filter ‘Sigma Filter Plus’ in one of my tasks. When I installed the plugin into my FIJI an ran the ImageJ macro, the filter processes the image. However when I am trying to run the same on Java Eclipse, it doesn’t run the filter and displays the following error:

Unrecognized command: “Sigma Filter Plus”

I am facing the same issue with Kuwahara and Space Noise Reduce filters.

Unrecognized command: "Kuwahara Filter"
Unrecognized command: “Space Noise Reduce”

How do I resolve this issue?

Note: I have installed all the needed .java and .jar files w.r.t the above filters into my source projects.


#2

Hi,

Are you working on a ImageJ1 style plugin? In that case I think the problem is that when ImageJ is launched from the IDE, it’s looking for the plugins from the wrong folder.

Have a look at this example:

If you just need to run your plug-in to test it, create a main() method with

	public static void main(String[] args) {
		// start ImageJ
		new ImageJ();

		// open an image (if needed)
		ImagePlus image = IJ.openImage("path/to/a/test/image.jpg");
		image.show();

		// run your plugin
		IJ.runPlugIn(My_Plugin.getClass().getName(), "");
	}

If you also want the plug-ins to display in the menu when ImageJ is launched from the Eclipse, set the “plugins.dir” property (before calling new ImageJ())

		// set the plugins.dir property to make the plugin appear in the Plugins menu
		Class<?> clazz = My_Plugin.class;
		String url = clazz.getResource("/" + clazz.getName().replace('.', '/') + ".class").toString();
		String pluginsDir = url.substring("file:".length(), url.length() - clazz.getName().length() - ".class".length());
		System.setProperty("plugins.dir", pluginsDir);

Best regards,
Richard


Run plugin from java/scala program
#3

Hi Richard,

Thanks for the quick reply. I implemented your code and output pops up the filter windows like it used to in ImageJ. Does this mean Eclipse is able to look for plugins in the correct folder or that’s ImageJ plugin being called?

Here’s a snippet of my code which isn’t running -

 IJ.runPlugIn(Gchannel, "Sigma Filter Plus","radius=3 use=1 minimum=0.1 outlier");
 //IJ.run(Gchannel, "Sigma Filter Plus","radius=3 use=1 minimum=0.1 outlier");

Thanks and Regards,
kbimagej


#4

Sorry for the belated reply

The line

launches the plugin. To see if the plug-in folder is set up correctly, and that the plug-ins get populated, remove the line, run the main() method (to launch ImageJ from Eclipse), and then check the menu path you specify in your plugins.config file.


#5

Hi Richard,

Thanks for the reply. I got the filter working for now. But the issue is that it doesn’t run in headless mode. The filter window keeps popping up and I have to manually feed in the filter parameters. How do I make it run in headless mode?

Thanks and Regards,
kbimagej


#6

Sorry, I think I may have misunderstood your original question. Could you explain again, what you want to accomplish, please? You want to launch your plug-in from Eclipse, and run it in ImageJ in headless mode?


#7

@rimadoma

Precisely. Sigma_Filter_Plus, a filter plugin is available as a .class file on the FIJI website. I want to use this plugin in Eclipse and run the filter in headless mode.

Thanks and Regards,
kbimagej


#8

Dear @kbimagej,

could please post the part of the code that you are using to execute the Sigma Filter Plus? Otherwise, we are not able to provide proper support.

Best,
Stefan


#9

Class<?> sfp= Sigma_Filter_Plus.class;
IJ.runPlugIn(Inpimg, sfp.getName(),"radius=3 use=1 minimum=0.1 outlier");

Here Inpimg is an 8-bit image.


#10

I assume that the issue is with IJ.runPlugIn(). You should be able to execute the following Groovy script in the Script Editor of a Fiji installation that has the Sigma_Filter_Pluss.class in its plugins/ directory:

import ij.IJ;

imp = IJ.getImage();
IJ.run(imp, "Sigma Filter Plus", "radius=5 use=2 minimum=0.2 outlier");

Hence, I would try to avoid IJ.runPlugIn() which seems to always call showDialog() (which you don’t want).


#11

I just tried using IJ.run(imp, "Sigma Filter Plus", "radius=5 use=2 minimum=0.2 outlier");. The filter isn’t implemented on the image and it just skips the calling but filter window doesn’t pop up.

I get a comment in the console window stating this:

Unrecognized command: “com.imageproc.Sigma_Filter_Plus”


#12

Ok I think your problem is that you are not setting up the plugins directory in your system when you are debugging/launch it with Eclipse.
I usually do that in this way, look in the Debugging method part (and set your fiji/plugins directory path on your computer):

import ij.IJ;
import ij.ImageJ;
import ij.ImagePlus;
import ij.plugin.PlugIn;


public class Sigma_filter_example implements PlugIn {

	@Override
	public void run(String arg) {		
		
			ImagePlus imp = IJ.openImage("https://imagej.nih.gov/ij/images/clown.jpg");
			IJ.run(imp, "Sigma Filter Plus", "radius=6 use=5 minimum=0.1 outlier");
			imp.show();
			
	     
	}


	/**
	 * Main method for debugging.
	 *
	 * For debugging, it is convenient to have a method that starts ImageJ, loads an
	 * image and calls the plugin, e.g. after setting breakpoints.
	 *
	 * @param args unused
	 */
//** DEBUGGING METHOD
public static void main(String[] args) {
	Class<?> clazz = Sigma_filter_example.class;
	String pluginsDir = "/Applications/Fiji.app/plugins";   //!!! THIS IS THE SETTING PART !!!
	System.setProperty("plugins.dir", pluginsDir);
	// start ImageJ
	new ImageJ();
	
	// run the plugin
	IJ.runPlugIn(clazz.getName(), "");
}
}

I’ve just tried it in Eclipse and it works.
I’ve setted up with maven and pom the dependencies (https://github.com/imagej/example-legacy-plugin) but honestly for this little example I think it could be not necessary do that.
For me it’s comfy since I’ve already some other projects done with maven and I just duplicated one of them changing some names.

Hoping to being helpful,
have a nice day
Emanuele Martini


Standard Deviation of a Image
#13

I just tried using IJ.run(imp, “Sigma Filter Plus”, “radius=5 use=2 minimum=0.2 outlier”);. The filter isn’t implemented on the image and it just skips the calling but filter window doesn’t pop up.

I get a comment in the console window stating this:

Unrecognized command: “com.imageproc.Sigma_Filter_Plus”


#14

reposting because @kbimagej wasn’t able to read it

Ok I think your problem is that you are not setting up the plugins directory in your system when you are debugging/launch it with Eclipse.
I usually do that in this way, look in the Debugging method part (and set your fiji/plugins directory path on your computer):

import ij.IJ;
import ij.ImageJ;
import ij.ImagePlus;
import ij.plugin.PlugIn;


public class Sigma_filter_example implements PlugIn {

	@Override
	public void run(String arg) {		
		
			ImagePlus imp = IJ.openImage("https://imagej.nih.gov/ij/images/clown.jpg");
			IJ.run(imp, "Sigma Filter Plus", "radius=6 use=5 minimum=0.1 outlier");
			imp.show();
			
	     
	}


	/**
	 * Main method for debugging.
	 *
	 * For debugging, it is convenient to have a method that starts ImageJ, loads an
	 * image and calls the plugin, e.g. after setting breakpoints.
	 *
	 * @param args unused
	 */
//** DEBUGGING METHOD
public static void main(String[] args) {
	Class<?> clazz = Sigma_filter_example.class;
	String pluginsDir = "/Applications/Fiji.app/plugins";   //!!! THIS IS THE SETTING PART !!!
	System.setProperty("plugins.dir", pluginsDir);
	// start ImageJ
	new ImageJ();
	
	// run the plugin
	IJ.runPlugIn(clazz.getName(), "");
}
}

I’ve just tried it in Eclipse and it works.
I’ve setted up with maven and pom the dependencies (https://github.com/imagej/example-legacy-plugin) but honestly for this little example I think it could be not necessary do that.
For me it’s comfy since I’ve already some other projects done with maven and I just duplicated one of them changing some names.

Hoping to being helpful,
have a nice day
Emanuele Martini