我正在尝试在ImageJ上创建一个插件,在ROI内部创建一个10像素宽的帧。我无法做到这一点,到目前为止,我所拥有的代码只是在整个空间中填充ROI中的10个像素。我的代码如下。
import ij.*;
import ij.plugin.filter.PlugInFilter;
import ij.process.*;
import java.awt.*;
public class Frame implements PlugInFilter {
public int setup(String arg, ImagePlus imp) {
if (arg.equals("about"))
{showAbout(); return DONE;}
return DOES_8G+DOES_STACKS+SUPPORTS_MASKING;
}
public void run(ImageProcessor ip) {
byte[] pixels = (byte[])ip.getPixels();
int width = ip.getWidth();
Rectangle r = ip.getRoi();
int offset, i;
for (int y=r.y+10; y<(r.y+r.height)-10; y++) {
offset = y*width;
for (int x=r.x+10; x<(r.x+r.width)-10; x++) {
i = offset + x ;
pixels[i] = (byte)(255);
}
}
}
答案 0 :(得分:0)
为什么要尝试硬(即低级API)方式?
使用ImageJ的command recorder(插件&gt;宏&gt;记录... 并将“记录:”设置为 Java ),您可以快速获得
之后需要的Java代码代码如下所示:
import ij.IJ;
import ij.ImagePlus;
import ij.plugin.frame.RoiManager;
// [...]
RoiManager rm = RoiManager.getInstance();
if (rm==null) rm = new RoiManager();
rm.runCommand("Deselect");
if (rm.getCount() > 0) rm.runCommand("Delete");
ImagePlus imp = IJ.getImage();
// imp.setRoi(30, 50, 150, 100);
rm.addRoi(imp.getRoi());
IJ.run(imp, "Enlarge...", "enlarge=-10");
rm.addRoi(imp.getRoi());
rm.setSelectedIndexes(new int[]{0,1});
rm.runCommand("XOR");
IJ.run(imp, "Fill", "slice");
imp.show();