Login  Register

Threshold Selection Macro problem

Posted by Bertrand Vernay on Nov 23, 2009; 1:59pm
URL: http://imagej.273.s1.nabble.com/Threshold-Selection-Macro-problem-tp3688803.html

Dear all

 

I have the following macro for batch measurements of pixels intensity on
confocal stacks (16-bits) (see at the end of the email)

1-Open image stacks from a folder

2-Apply threshold duplicated image

3- Create selection from binary on original image

4- Measure pixel intensity within the selection

5- Save images + selection overlay

6- Save results table

 

Unfortunately if the threshold value is too high some slice will have no
pixels selected and the macro cannot create a selection and then stop.

Is there a way around this problem using macro language?

 

Thank you

 

Bertrand

 

----------------------------------------------------------------------------
-----------------------------------------

 

// MEASUREMENTS PARAMETERS

run("Set Measurements...", "area mean min display redirect=None decimal=3");

 

// SELECT INPUT AND OUTPUT FOLDERS

inputFolder = getDirectory("Choose the folder containing the files to
process");

 

 

// ENTER THRESHOLD VALUE

Min = getNumber("Threshold Minimum", Min);

Max = getNumber("Threshold Maximum", Max);

 

//DISPLAY YES/NO  STEPS

setBatchMode(true);


 

// HOW MANY FILES IN FOLDER

images = getFileList(inputFolder);

 

// APPLY THRESHOLD

for (i=0; i<images.length; i++) {

inputPath = inputFolder + images[i];

open(inputPath);

run("Clear Results");

title = getTitle;

run("Duplicate...", "title=temp duplicate");

setThreshold(Min, Max);

run("Threshold", "thresholded remaining black slice");

 

//CREATE SELECTION FOR EACH SLICE ON ORIGINAL IMAGE

            for (n=1; n<=nSlices; n++)  {

            setSlice(n);

            run("Create Selection");  

            selectWindow(title);

            setSlice(n);

            run("Restore Selection");

            run("Measure");

            run("Draw", "No");

            run("Select None");

            selectWindow("temp");

            run("Select None");

            }

 

// SAVE SELECTION MEASURED ON IMAGES + THRESHOLD VALUES USED

outputPath = inputFolder + images[i];

outputPath = substring(inputPath,0,lengthOf(inputPath)-4)+"-"+Min+"-"+Max;

selectWindow(title);

setSlice(1);

setTool("text");

setFont("SansSerif", 12, " antialiased");

makeText("Min =" +Min, 15, 15);

drawString("Min =" + Min, 15, 15);

setTool("text");

makeText("Max =" + Max, 85, 15);

drawString("Max =" + Max, 85, 15);

saveAs("tiff", outputPath);

 

//SAVE MEASUREMENTS TABLE

selectWindow("Results");

outputPath = inputFolder + images[i];

outputPath = substring(inputPath,0,lengthOf(inputPath)-4)+"-"+Min+"-"+Max;

saveAs("measurements", outputPath);

run("Clear Results");

close();

close();

}

setBatchMode(false);

 

--
Dr Bertrand Vernay
Microscopy Senior Research Associate
Developmental Biology Unit
UCL Institute of Child Health
30 Guilford Street
London WC1N 1EH, UK
 
Tel :  (+44)  020 7905 2224 (direct line)
       (+44)  020 7242 9789 (ICH switchboard)
 
Fax:    (+44)  020 7831 4366
 
E-mail:
<https://webmail.ich.ucl.ac.uk/src/compose.php?send_to=b.vernay%40ich.ucl.ac
.uk> [hidden email]
 
 
<http://www.ich.ucl.ac.uk/services_and_facilities/lab_services/confocal_micr
oscopy_core_facility/index.html>
http://www.ich.ucl.ac.uk/services_and_facilities/lab_services/confocal_micro
scopy_core_facility/index.html