ImageJ には、画像をセグメント化するために色 (RGB または HSB) 間の関係を調べるプラグインがいくつかあります。それらはうまく機能しますが、非常に一般的であり、ダイアログにはかなりの数のチェックボックスとスライダーが定義されています。
すぐに何百もの画像を手動で処理する必要がありますが、設定を微調整するだけでよいように、画像を見て特定のプリセットをロードできるようにしたいと考えています。一連のボタンまたはドロップダウン メニューを追加して、選択時にすべてのチェックボックス/スライダーの設定をその設定で定義されたプリセット値に変更したいと思います。
以下は、ダイアログ ボックスを定義する方法ですが、通常の設定ボックス/スライダーの約 20% を使用します。
import ij.*;
import ij.gui.*;
import ij.process.*;
import ij.plugin.filter.*;
import java.awt.*;
import java.util.*;
import java.awt.event.*;
import java.lang.Math.*;
public class Hue_colors_filter_ implements ExtendedPlugInFilter, DialogListener {
//private ImagePlus imp; // Original image
private ImageStack sstack; // Stack result
private int width; // Width of the original image
private int height; // Height of the original image
private int size; // Total number of pixels
private float[] c1, c2, c3; // Colour space values
private float[] rf, gf, bf; // r, g, b values
private String colourspace; // Colour space chosen
private String title; // Name of the original image
private String n1, n2, n3; // Names for every layer on the stack
private int r,g,b; // rgb values as integers
ImagePlus imp = null;
private static int black = 10;
private static boolean blackshow = true;
private static boolean magentashow = true;
public int setup(String arg, ImagePlus imp) {
if (imp == null) {
IJ.noImage();
return DONE;
}
if (arg.equals("about")) {
showAbout();
return DONE;
}
this.imp = imp;
return DOES_RGB;
}
public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr) {
GenericDialog gd = new GenericDialog(command);
gd.addSlider("Black_max: ", 0., 256., black);
gd.addCheckbox("_Black", blackshow);
gd.addCheckbox("_Magenta", magentashow);
gd.addPreviewCheckbox(pfr);
gd.addDialogListener(this);
gd.showDialog();
if (gd.wasCanceled()) return DONE;
IJ.register(this.getClass());
return IJ.setupDialog(imp, DOES_RGB);
}
public boolean dialogItemChanged(GenericDialog gd, AWTEvent e) {
black = (int)gd.getNextNumber();
blackshow = gd.getNextBoolean();
magentashow = gd.getNextBoolean();
return true;
}
public void run(ImageProcessor ip) {
try{
//do some stuff
} // end of try
catch(Exception e){
IJ.error("Runtime Error", e.getMessage());
}
}
public void setNPasses (int nPasses) {
}
public void showAbout() {
IJ.showMessage("Hello World!");
}
}
私が Java の初心者だとわからない場合は、. ヘルプやポインタをいただければ幸いです。