Login  Register

Complex (for me!) macro - advice needed

Posted by ross oshea on Sep 12, 2007; 7:28am
URL: http://imagej.273.s1.nabble.com/Complex-for-me-macro-advice-needed-tp3698389.html

Hi. I am trying to put together a macro to do batch processing of images in order to count cells, but am not very experienced in this process and can't get it to do all I want. The threshold / erode / watershed steps seem to work well for isolating individual cells, so I would like to be able to put together the steps listed below. I have added some bits from the "Record Macro" function to the BatchMeasure macro but I'm sure this is NOT the most elegant solution!

1) ask user to enter the folder containing the images and, for each image:
2) convert to 8-bit
3) ask user to enter threshold values
4) erode image
5) watershed image
6) ask user to set particle size * this is the one I can't get, so it's set at 165 - 2000 in my macro!

The following macro works except for point 6 - can anyone please let me know how to include parameters for particle size? Any improvements in the macro would also be most useful.

My pathetic Batch Measure Macro:

    dir = getDirectory("Choose a Directory ");
    list = getFileList(dir);
    start = getTime();

  width=512; height=512;
  Dialog.create ("Threshold");
  Dialog.addNumber("Lower_Threshold:", 0);
  Dialog.addNumber("Upper_Threshold:", 255);
  Dialog.show();
  Lower_Threshold = Dialog.getNumber();
  Upper_Threshold = Dialog.getNumber();

    setBatchMode(true);
    for (i=0; i<list.length; i++) {
        path = dir+list[i];
        showProgress(i, list.length);
        if (!endsWith(path,"/")) open(path);
        if (nImages>=1) {
          run("8-bit");
          setAutoThreshold();
          //run("Threshold...");
          setThreshold(Lower_Threshold, Upper_Threshold);
          run("Convert to Mask");
          run("Erode");
          run("Watershed");
          run("Analyze Particles...", "size=165-2000 circularity=0.00-1.00 show=Masks summarize");
        }
    }