Login  Register

Re: Biggest object measure

Posted by Josep M. Lanau on May 30, 2008; 1:08pm
URL: http://imagej.273.s1.nabble.com/Biggest-object-measure-tp3696071p3696073.html

Hello,

I managed to buid a macro to measure the biggest object of an image. It
uses G.Landini's KeepLargestParticlePixel macro: duplicates the image,
binarizes, deletes all particles except the biggest, selects the object and
measures inside the selection in the original image.

It still does not work, there are some problems when I try to batch measure
a whole directory.

- The results of a previous image is not kept in the results table, so
after batch measuring all the directory, there only remains the last
measure in the results table.
- G.Landini's macro keeps asking in a dialog box if particles are black or
white ones, so you must click once for each image that is measured.

Does anyone have a hint on these?

Here is my macro project (comments in catalan, sorry). It asks for a
threshold level, asks which is the directory to be measured, and asks you
if you want to calibrate before processing (you must click on "global
calibration", then). Hey, it's a beginner's macro!

All coments (if any ;) ) will be welcome. Thank you in advance.

JM Lanau


//                ***** BATCH MEASURE BIGGEST *****
// JML 01-Març-2008

macro "Batch Measure Biggest" {

// setBatchMode(true);

if (nImages>0) {
   getThreshold(lower, upper);
   }
else {
   lower=0;
   upper=255;
   }

Dialog.create("Llindar mínim");
Dialog.addNumber("Threshold mínim",lower);
Dialog.show();
lower=Dialog.getNumber();

Dialog.create("Llindar màxim");
Dialog.addNumber("Threshold màxim",upper);
Dialog.show();
upper=Dialog.getNumber();

    dir = getDirectory("Escull el directori a mesurar");
    list = getFileList(dir);

Dialog.create("Calibrem?");
Dialog.addMessage ("Threshold establert a "+lower+" "+upper);
Dialog.addCheckbox ("Calibrar",1)
Dialog.show();

calibro=Dialog.getCheckbox();

    for (i=0; i<list.length; i++) {
        path = dir+list[i];
        showProgress(i, list.length);
        if (!endsWith(path,"/")) open(path);
          if (nImages>=1) {
                 if (calibro==1) {
                      Dialog.create("ATENCIÓ!");
                      Dialog.addMessage ("Recorda marcar la casella
global!!");
                      Dialog.show();
                      run("Calibrate...");
                      close();
                      calibro=0;
                 }
           
run("Duplicate...", "title=seed.tif");
setThreshold(0, 254);
run("Make Binary", "thresholded remaining black");
run("KeepLargestParticlePixels ");
setThreshold (lower, upper);
run("Create Selection");
run("ROI Manager...");
roiManager("Add");
close();
roiManager("Select", 0);
run("Measure");
roiManager("Delete");
close();
          }
        }
    }

beep();