| 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.
|