Welcome, guest | Sign In | My Account | Store | Cart

ImageJ (http://rsb.info.nih.gov/ij/) is a very good image processing program which can be extended using plugins. It is also possible to write ImageJ plugins in jython and generate a class file. This plugin implements an image inverter.

Python, 16 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
import ij

class Inverter_py(ij.plugin.filter.PlugInFilter):
    def setup(self,arg, imp):
        """@sig public int setup(String arg, ij.ImagePlus imp)"""
        return ij.plugin.filter.PlugInFilter.DOES_8G

    def run(self,ip):
        """@sig public void run(ij.process.ImageProcessor ip)"""
        pixels = ip.getPixels()
        width = ip.getWidth()
        r = ip.getRoi()
        for y in range(r.y,r.y+r.height):
            for x in range(r.x,r.x+r.width):
                i = y*width + x;
                pixels[i] = 255-pixels[i]

When you compile the file with jythonc you should use the following option switches: jython -w "C:\ImageJ\plugins\Jython" -C "C:\ImageJ\jikes" -J "-bootclasspath C:\ImageJ\jre\lib\rt.jar -nowarn"

thanks for this tip to Edoardo ''Dado'' Marcora, Ph.D. (private communication)

2 comments

Edoardo Marcora 18 years, 9 months ago  # | flag

A different approach to ImageJ-Jython integration. I change my approach to ImageJ-Jython integration. You can find an HOWTO at http://marcora.caltech.edu/jython_imagej_howto.htm. Using this approach you don't need to compile the Python/Jython source code using jythonc anymore. It makes life much much easier while developing the plugin. You can always compile it when you're done with the development if performance is an issue (but I haven't run any benchmark... it seems fast enough to me without compilation).

Hope this helps,

Edoardo "Dado" Marcora

Albert Cardona 18 years, 5 months ago  # | flag

further jython integration into ImageJ. I've created some ImageJ plugins that play the role of jython utilities. Any Jython script placed under ImageJ/plugins/Jython appears listed in the Plugins/Jython menus, and further, another plugin works as a dynamic interpreter for ImageJ which provides full java and ImageJ access while scripting ImageJ in a pythonesque way. Check http://www.pensament.net/java/other_plugins.html for all details.