Particle analyzer and ROI manger

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

Particle analyzer and ROI manger

Susanna Trollvad
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 done
how to access the ROIs in the ROI manager?

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

243-3.1.jpg (26K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Particle analyzer and ROI manger

Arne Seitz
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/
---------------------------------------------------------------
Reply | Threaded
Open this post in threaded view
|

Re: Particle analyzer and ROI manger

Susanna Trollvad
2011/5/17 Seitz Arne <[hidden email]>

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

This also works, but I would like to be able to do it without calling the
"Analyze particles" menu command.

I am a bit confused about how the code below works. How can you call the
getInstance method to the RoiManger if you havent first created a RoiManger
object? Is that something that is done but not shown in the code below? But
then what is the point of the getInstance() function because then you
already have the RoiManager object.

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/
> ---------------------------------------------------------------
>
Reply | Threaded
Open this post in threaded view
|

Re: Particle analyzer and ROI manger

Arne Seitz
> I am a bit confused about how the code below works. How can you call
> the
> getInstance method to the RoiManger if you havent first created a
> RoiManger
> object? Is that something that is done but not shown in the code below?
> But
> then what is the point of the getInstance() function because then you
> already have the RoiManager object.
 
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).
To get a reference to this RoiManager you can use
        RoiManager.getInstance();

With
        RoiManager.getInstance().getROIs()
you can get the ROIs as Hashtable

Alternatively you can also use:
        RoiManager.getInstance().getRoisAsArray()
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/
> > ---------------------------------------------------------------
> >
Reply | Threaded
Open this post in threaded view
|

Re: Particle analyzer and ROI manger

Jan Eglinger-3
In reply to this post by Susanna Trollvad
Hi Susanna,

On 17.05.2011 3:52 PM, Susanna Trollvad wrote:
> 2011/5/17 Seitz Arne <[hidden email]>
>> 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.
>
> This also works, but I would like to be able to do it without calling the
> "Analyze particles" menu command.

what I do in Javascript to invoke the "Analyze particles" command
without showing a window is the following (mind the line breaks
introduced by the mailer). Maybe you can transfer this to your Java plugin.

// JavaScript code snippet

 var pa = new ParticleAnalyzer(ParticleAnalyzer.SHOW_MASKS +
ParticleAnalyzer.INCLUDE_HOLES, 0, rt, params[MIN_SIZE],
Double.POSITIVE_INFINITY);
 pa.setHideOutputImage(true);
 pa.analyze(imp1, ip1);
 var imp2 = pa.getOutputImage();

// end of snippet

For setting the options, see the Javadoc on
http://pacific.mpi-cbg.de/javadoc/ij/plugin/filter/ParticleAnalyzer.html

Hope that helps,
Jan