Login  Register

Re: Filters Public API

Posted by Wayne Rasband on Jun 15, 2008; 4:56am
URL: http://imagej.273.s1.nabble.com/Filters-Public-API-tp3695891p3695892.html

> Hello,
> we are trying to embed imagej to our application, but most of the  
> filters
> don't have a public api that can be used outside imagej. The only  
> way to
> access them is only through IJ.run("Filter....", "args"), having to  
> set the
> current image everytime. The latter is also dangerous in a  
> multithreaded
> environment.
> If there is another way to apply a filter to a speceific image  
> please let me
> know.
>
> I could make the methods public myself, but I would like to ask if  
> it will
> be in the main distribution.

The 1.41f daily build adds versions of the IJ.run(), IJ.save() and  
IJ.saveAs() that take an ImagePlus as the first argument. This  
example uses these new methods to open an image, process it, save it,  
then reopen and display the processed image:

    if (IJ.getVersion()<"1.41f")
        IJ.error("This script requires v1.41f or later");
    dir = IJ.getDirectory("home");
    img = IJ.openImage(dir+"test.jpg");
    IJ.run(img, "Unsharp Mask...", "radius=3 mask=0.6");
    IJ.run(img, "Flip Horizontally");
    IJ.run(img, "8-bit Color", "number=256");
    IJ.save(img, dir+"test.png");
    img = IJ.openImage(dir+"test.png");
    img.show();

You can run this example by pasting it into a text window and  
pressing ctrl-j (Macros>Evaluate JavaScript).

ImageJ uses a hash table with thread objects as keys and option  
strings as values to make the passing of the run() options thread  
safe, a technique suggested by Albert Cardona.

-wayne