Image Inverter

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:
  1. Filter plugins must implement the PlugInFilter interface.
  2. The setup() method is called one time when the plugin starts but run() is called repeatedly, once for each image in the stack.
  3. User plugins do not use the package statement;
  4. Plugins residing in the "plugins" folder, and with at least one underscore in their name, are automatically installed in the PlugIns menu.
  5. Plugins can be installed in other menus by packaging them as JAR files.
  6. The class name ("Image_Inverter") and file name ("Image_Inverter.java") must be the same.
  7. This filter works with selections, including non-rectangular selections.
  8. It will be called repeatedly to process all the slices in a stack.
  9. It supports Undo for single images.
  10. This plugin does not work with 32-bit (float) images with non-integer pixel values. Use getf() and setf() to work with such images.
  11. "~" is the bitwise complement operator.
See Also: Inverter_.java - the original version, which was faster, but a lot more complicated

|Plugins | Home |