How ImageJ process non-rectangular ROIs?
Posted by panovr on
URL: http://imagej.273.s1.nabble.com/How-ImageJ-process-non-rectangular-ROIs-tp3701627.html
Hi,
a simple inverter plugin which can deal with ROIs may like these:
===========================================================================
public class Simple_Inverter implements PlugInFilter {
ImagePlus imp;
public int setup(String arg, ImagePlus imp) {
if (arg.equals("about")) {
showAbout();
return DONE;
}
this.imp = imp;
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; y < (r.y + r.height); y++) {
offset = y * width;
for (int x = r.x; x < (r.x + r.width); x++) {
i = offset + x;
pixels[i] = (byte)(255 - pixels[i]);
}
}
}
}
}
===========================================================================
When I use "Elliptical" tool to select a non-rectangular ROI in the
image, then invoke this plugin, and ImageJ can process the non-rectangular
ROI correctly (the elliptical region was inverted).
My question is: in my program, I use "Rectangle" to represent general
ROIs including rectangular and non-rectangular. But how ImageJ can process
non-rectangular ROI by "Rectangle"?
Thanks!
Yili Zhao