Segmentation macro problems, still

Posted by Weller Andrew Francis on
URL: http://imagej.273.s1.nabble.com/Segmentation-macro-problems-still-tp3702363.html

Dear all,

Can anyone see any problems with the following macro? I can't for the
life of me get it doing what I want it to do.

In essence I want my segmented particle (bright foreground, black
background) and its associated ROI saved, but all I keep getting is
black and white images (black particle + specks, white background). I've
tried all various settings I can think of (threshold, etc), but nothing.
My current problem is this:

The 'Particle Analyzer' box comes up with "A threshold image or 8-bit
binary image is required. Threshold levels can ve set using the Image ->
Adjust -> Threshold tool." I am doing this (see macro), but the strange
thing is, it seems to work manually...?!

Many thanks, Andy

<MACRO>

   setBatchMode(true);
   img = getImageID;

   setAutoThreshold();
   getThreshold(lo, up);
   lo = lo-30;
      if (lo<0) {
         lo = 0;
         }
   setThreshold(lo, up);
   run("Threshold", "thresholded remaining");

   run("Analyze Particles...", "size=10000-Infinity
circularity=0.00-1.00 show=Masks clear include");
   mask = getImageID;
   run("Copy");
   setPasteMode("AND");
   selectImage(img);
   run("Paste");
   resetThreshold();
   save(fileName+".tif");
   selectImage(mask);
   run("Create Selection"); // requires 1.37j
   selectImage(img);
   run("Restore Selection");
   save(fileName+".roi");