Login  Register

Re: Particle analyzer and ROI manger

Posted by Arne Seitz on May 17, 2011; 12:46pm
URL: http://imagej.273.s1.nabble.com/Particle-analyzer-and-ROI-manger-tp3684572p3684573.html

Hi Susanna,

 

> I want to create a plugin were I first turn my picture into a HSB
> stack, choose the brightness slice and delete the other two, then
> threshold to a preset value, and then do what the "Analyze particles"
> command from the menu without the user having to give any input. And
> then I want to rotate the ROIs that get stored in the ROI manager.
>
> I have made it work up to the "Analyze particle" step which I'm not
> quite sure how to do. (But I'm not quite satisfied by the thresholding)
>
> Does anyone know how to do the "Analyze particles" step? Or when that's

One way of doing the analysis is by running the command:
IJ.run(imp,"Analyze Particles...", "size=0.12-Infinity circularity=0.00-1.00 show=Nothing exclude clear include add slice");
With imp being the IaagePlus you wanted to analyse.

> 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/
---------------------------------------------------------------