How to run this code

sairam to all

can any one tell me how to run this class

package myWards;

import ij.IJ;
import ij.ImagePlus;
import ij.plugin.PlugIn;
import ij.process.ImageProcessor;

public class vi_opensave_imagev1 implements PlugIn{
	public void run(String arg) {;											//This method ( ) displays a window to select an image, displays it and makes it active
		ImagePlus myImPlus = IJ.getImage();					//This method ( IJ.getImage() ) recuperates the ImagePlus of the active Image
		ImageProcessor myIp = myImPlus.getProcessor();		//This method (.getImageProcessor() ) recuperates the ImageProcessor of a given ImagePlus

//Here We may write a task done by the plugin. 
		myIp.findEdges();									//This method ( .findEdges() ) applies the sobel filter to the active Image
		myImPlus.updateAndDraw();							//This method ( .updateAndDraw() ) updates the modifications of the ImageProcessor of a given ImagePlus"Save");										//This method ("String command") ) This method executes the ImageJ function, macro on plugin with the given command.

Where does the source come from? You need to give us more infos if you want to get a profound answer.

There is a Java package declaration package myWards; in the first line which indicates that this class belongs to a package.

However, if you remove the package declaration you can do the following.

Just save the file to the ImageJ plugins directory (with *.java extension). Then open the file, compile and run it:

Plugins->Compile And Run…

@lokesh_andhavarapu You don’t have to remove the package declaration. But in order to compile the Java code, the .java file needs to be saved in a folder hierarchy reflecting the package hierarchy (i.e. package my.package; would require the file to be in ./my/package/.

Note that it doesn’t need to be in the plugins folder, it can be anywhere on your file system, as long as the parent directories coform to the package name as above. Putting it into ./plugins/ or a subfolder therein will however make the plugin show up as a menu command upon the next start of ImageJ.

Also note that the file name needs to be exact same as the class name, i.e. you need to save the file as

In an up-to-date Fiji installation, it’s sufficient to paste the code in the script editor, save the file as described above, and click the Run button.

1 Like

Right, for beginners this is often a cause for compilation errors.

@imagejan thanks for the addition.