Re: Iterator over Roi points anywhere

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: Iterator over Roi points anywhere

Joost Willemse
>
>
>
You can use the getRoisAsArray to get the wanted ROI from the roi manager,

by then using the getBounds you can get the bounding rectangle and then you
can iterate over the pixels within the ROIs by using the contains method of
the ROI.

See this example:

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

public class RoiIt extends RoiManager implements PlugIn {
static final long serialVersionUID=44L;
RoiManager rm = RoiManager.getInstance();
ImagePlus imp = IJ.openImage("http://imagej.nih.gov/ij/images/blobs.gif");

public void run(String arg) {
imp.show();
IJ.setAutoThreshold(imp, "Default");
Prefs.blackBackground = true;
IJ.run(imp, "Convert to Mask", "");
IJ.run(imp, "Analyze Particles...", "size=200-1000000 circularity=0.00-1.00
show=Nothing exclude add");
IJ.run(imp, "RGB Color", "");
Roi[] arrroi=rm.getRoisAsArray();
for (int k=0;k<arrroi.length;k++){
Roi thisroi=arrroi[k];
Rectangle thisBound = thisroi.getBounds();
IJ.setForegroundColor(255, 0, 0);
for (int
i=(int)thisBound.getX();i<((int)thisBound.getX()+(int)thisBound.getWidth());i++){
for (int
j=(int)thisBound.getY();j<((int)thisBound.getY()+(int)thisBound.getHeight());j++){
if (thisroi.contains(i,j)){
IJ.run(imp, "Specify...", "width=1 height=1 x="+i +" y="+j);
IJ.run(imp, "Fill", "slice");
}
}
}
}
}
}

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html