Author: Wayne Rasband (wsr at nih.gov) History: 2000/11/03: First version
2006/07/01: Simplified; uses get() and set() methods
Requires: ImageJ 1.37j or later Source: Image_Inverter.java Installation: Copy Image_Inverter.class to the plugins folder and restart ImageJ. Description: This example plugin filter inverts the current image. Here is what the code looks like: public class Image_Inverter implements PlugInFilter { public int setup(String arg, ImagePlus imp) { return DOES_ALL+DOES_STACKS+SUPPORTS_MASKING; } public void run(ImageProcessor ip) { Rectangle r = ip.getRoi(); for (int y=r.y; y<(r.y+r.height); y++) for (int x=r.x; x<(r.x+r.width); x++) ip.set(x, y, ~ip.get(x,y)); } }A few things to note:
- Filter plugins must implement the PlugInFilter interface.
- The setup() method is called one time when the plugin starts but run() is called repeatedly, once for each image in the stack.
- User plugins do not use the package statement;
- Plugins residing in the "plugins" folder, and with at least one underscore in their name, are automatically installed in the PlugIns menu.
- Plugins can be installed in other menus by packaging them as JAR files.
- The class name ("Image_Inverter") and file name ("Image_Inverter.java") must be the same.
- This filter works with selections, including non-rectangular selections.
- It will be called repeatedly to process all the slices in a stack.
- It supports Undo for single images.
- This plugin does not work with 32-bit (float) images with non-integer pixel values. Use getf() and setf() to work with such images.
- "~" is the bitwise complement operator.
See Also: Inverter_.java - the original version, which was faster, but a lot more complicated