import ij.*;
import ij.gui.*;
import ij.plugin.frame.*;
import java.awt.*;
import java.awt.event.*;

public class Cell_Segmentation extends PlugInFrame {

  public final int WINDOW_WIDTH  = 140;
  public final int WINDOW_HEIGHT = 90;

  // External
  public RoiManager roiMgr;

  // Internal
  static PlugInFrame instance;

  public Cell_Segmentation() {
    super("Cell Seg");

    // Open ROI Manager
    roiMgr = RoiManager.getInstance();
    if (roiMgr == null)
      roiMgr = new RoiManager();

    // Open Cell Seg
    if (instance != null)
      instance.toFront();
    else {
      WindowManager.addWindow(this);
      setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
      GUI.center(this);
      setVisible(true);
      instance = this;
    }
  }

  // Overrides Component.addNotify(). getInsets() must be called after
  // addNotify() or it will not return the title bar height.
  public void addNotify() {
    super.addNotify();

    int xm = 20; // x margin
    int ym = getInsets().top + 25; // y margin
    int yw = 25;
    int yi = 10;

    setLayout(null);
    setForeground(java.awt.Color.darkGray);
    setResizable(false);

    Button segmentBtn = new Button("Segment");
    // segmentBtn.addActionListener(null);
    // segmentBtn.addKeyListener(null);
    segmentBtn.setName("segment");
    segmentBtn.setBounds(xm, ym, WINDOW_WIDTH - xm*2, yw);
    add(segmentBtn);

    // Button filterBtn = new Button("Filter");
    // filterBtn.addActionListener(null);
    // filterBtn.addKeyListener(null);
    // filterBtn.setName("filter");
    // filterBtn.setBounds(xm, ym + (yw + yi), WINDOW_WIDTH - xm*2, yw);
    // add(filterBtn);
  }

  // Overrides windowClosing in PluginFrame.
  public void windowClosing(WindowEvent e) {
    super.windowClosing(e);
    instance = null;
  }
}

@@ -19,24 +19,45 @@
 t ij.gui.*;%0A
+import ij.process.*;%0A
 import ij.pl
@@ -77,24 +77,32 @@
 %0Aimport 
-java.awt
+ij.plugin.filter
 .*;%0Aimpo
@@ -117,14 +117,8 @@
 awt.
-event.
 *;%0A%0A
@@ -152,14 +152,17 @@
 ion 
-extend
+implement
 s Pl
@@ -170,1247 +170,347 @@
 gInF
-rame
+ilter
  %7B%0A%0A  
-public final int WINDOW_WIDTH  = 140;%0A  public final int WINDOW_HEIGHT = 90;%0A%0A  // External%0A  public RoiManager roiMgr;%0A%0A  // Internal%0A  static PlugInFrame instance;%0A%0A  public Cell_Segmentation() %7B%0A    super(%22Cell Seg%22);%0A%0A    // Open ROI Manager%0A    roiMgr = RoiManager.getInstance();%0A    if (roiMgr == null)%0A      roiMgr = new RoiManager();%0A%0A    // Open Cell Seg%0A    if (instance != null)%0A      instance.toFront();%0A    else %7B%0A      WindowManager.addWindow(this);%0A      setSize(WINDOW_WIDTH, WINDOW_HEIGHT);%0A      GUI.center(this);%0A      setVisible(true);%0A      instance = this;%0A    %7D%0A  %7D%0A%0A  // Overrides Component.addNotify(). getInsets() must be called after%0A  // addNotify() or it will not return the title bar height.%0A  public void addNotify() %7B%0A    super.addNotify();%0A%0A    int xm = 20; // x margin%0A    int ym = getInsets().top + 25; // y margin%0A    int yw = 25;%0A    int yi = 10;%0A%0A    setLayout(null);%0A    setForeground(java.awt.Color.darkGray);%0A    setResizable(false);%0A%0A    Button segmentBtn = new Button(%22Segment%22);%0A    // segmentBtn.addActionListener(null);%0A    // segmentBtn.addKeyListener(null);%0A    segmentBtn.setName(%22segment%22);%0A    segmentBtn.setBounds(xm, ym, WINDOW_WIDTH - xm*2, yw);%0A    add(segmentBtn);%0A
+// External%0A  public ImagePlus  imp;%0A  public RoiManager roiMgr;%0A%0A  public int setup(String arg, ImagePlus imp) %7B%0A    this.imp = imp;%0A%0A    // Open ROI Manager%0A    roiMgr = RoiManager.getInstance();%0A    if (roiMgr == null)%0A      roiMgr = new RoiManager();%0A%0A    return DOES_ALL;%0A  %7D%0A%0A  public void run(ImageProcessor ip) %7B
 %0A    // 
 Butt
@@ -509,408 +509,54 @@
  // 
-Button filterBtn = new Button(%22Filter%22);%0A    // filterBtn.addActionListener(null);%0A    // filterBtn.addKeyListener(null);%0A    // filterBtn.setName(%22filter%22);%0A    // filterBtn.setBounds(xm, ym + (yw + yi), WINDOW_WIDTH - xm*2, yw);%0A    // add(filterBtn);%0A  %7D%0A%0A  // Overrides windowClosing in PluginFrame.%0A  public void windowClosing(WindowEvent e) %7B%0A    super.windowClosing(e);%0A    instance = null;%0A  %7D
+Put this line to validate%0A    ip.invert();%0A  %7D%0A
 %0A%7D%0A

Implement PlugInFilter instead