http://imagej.273.s1.nabble.com/Particle-analyzer-and-ROI-manger-tp3684572p3684576.html
> I am a bit confused about how the code below works. How can you call
I'm sorry because I forgot to mention that the code was assuming that there is an existing RoiManager (which might have been created with the "Analyze Particles" command).
In order to get the array of ROIs.
> When you use the "Analyze Particles" command it seems as though a
> RoiManager
> is created and a bunch of ROIs are stored in an array, and there is a
> method
> in RoiManager called getRoiAsArray(), which I think I would like to
> use. How
> would I do that?
>
> >
> > > done how to access the ROIs in the ROI manager?
> >
> > This is how I managed to get access to the ROIs of the ROi Manager.
> >
> > private void growROI(double grow){
> >
> > Hashtable RoiTab=RoiManager.getInstance().getROIs();
> >
> > Enumeration e = RoiTab.keys();
> > while (e.hasMoreElements()) {
> > Object key = e.nextElement();
> > Roi roi = (Roi) RoiTab.get(key);
> > Rectangle rect=roi.getBoundingRect();
> > int h=(int)grow*rect.height;
> > int w=(int)grow*rect.width;
> > rect.grow(h, w);
> > Roi nroi=new Roi(rect);
> > RoiTab.put(key, nroi);
> > }
> >
> > }
> >
> >
> >
> > >
> > > Here is what I have written so far:
> > >
> > > import ij.*;
> > > import ij.plugin.filter.PlugInFilter;
> > > import ij.process.*;
> > > import java.awt.*;
> > > import ij.plugin.filter.*;
> > > import ij.gui.*;
> > > import ij.measure.*;
> > > import ij.text.*;
> > > import java.util.*;
> > > import ij.plugin.Thresholder;
> > > import ij.plugin.filter.ParticleAnalyzer;
> > >
> > >
> > > public class Roi_test implements PlugInFilter, Measurements {
> > > ImagePlus imp;
> > > ImageConverter convert;
> > > ImageStack stacky;
> > > Thresholder treshy;
> > > ParticleAnalyzer party;
> > >
> > > public int setup(String arg, ImagePlus imp) {
> > >
> > > if (arg.equals("about")) {
> > > showAbout(); return DONE;
> > > }
> > >
> > > this.imp = imp;
> > > return DOES_RGB;
> > > }
> > >
> > > public void run(ImageProcessor ip) {
> > >
> > > int ht = imp.getHeight();
> > > int wd = imp.getWidth();
> > >
> > > ImagePlus dst = NewImage.createRGBImage("HSB", wd, ht, 1,
> > > NewImage.FILL_BLACK);
> > >
> > > ImageProcessor srcp = imp.getProcessor();
> > > ImageProcessor dstp = dst.getProcessor();
> > > int[] srcpix = (int[])srcp.getPixels();
> > > int[] dstpix = (int[])dstp.getPixels();
> > >
> > > Rectangle r = srcp.getRoi();
> > > //debug("roi bounds: "+r);
> > >
> > > for (int y=r.y; y<(r.y+r.height); y++) {
> > > for (int x=r.x; x<(r.x+r.width); x++) {
> > > int i = x + y*wd;
> > > dstpix[i] = srcpix[i];
> > > }
> > > }
> > > dst.show();
> > >
> > > //Convert to HSB and delete H and S slice
> > > convert = new ImageConverter(dst);
> > > convert.convertToHSB();
> > > stacky = dst.getImageStack();
> > > dst.setSlice(3);
> > > stacky.deleteSlice(1);
> > > stacky.deleteSlice(2);
> > >
> > > //Threshold
> > > //Use ThresholdtoSelection?
> > > dstp.setThreshold(10, 255, dstp.getLutUpdateMode());
> > > treshy = new Thresholder();
> > > treshy.run("Convert to Mask");
> > >
> > > //Analyze particles
> > > party = new ParticleAnalyzer();
> > > party.analyze(dst);
> > > }
> > >
> > > void showAbout() {
> > > IJ.showMessage("AHHH!!");
> > > }
> > >
> > > }
> > >
> > >
> > >
> > > //Susanna
> >
> > Cheers Arne
> >
> >
> > ---------------------------------------------------------------
> > Dr. Arne Seitz
> > Head of Bioimaging and Optics Platform (PT-BIOP)
> > Ecole Polytechnique Fédérale de Lausanne (EPFL)
> > Faculty of Life Sciences
> > Station 15, AI 0241
> > CH-1015 Lausanne
> >
> > Phone: +41 21 693 9618
> > Fax: +41 21 693 9585
> >
http://biop.epfl.ch/> > ---------------------------------------------------------------
> >