Login  Register

Particle analyzer and ROI manger

Posted by Susanna Trollvad on May 17, 2011; 11:33am
URL: http://imagej.273.s1.nabble.com/Particle-analyzer-and-ROI-manger-tp3684572.html

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