Threshold Selection Macro problem

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Threshold Selection Macro problem

Bertrand Vernay
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

 
Reply | Threaded
Open this post in threaded view
|

Opening Zeiss LSM files in a macro

Bertrand Vernay
Dear all

I do not manage to open .lsm5 files when running a macro using the
open(path) command. The macro works fine with tiff files. ImageJ does open
the LSM5 file without problem otherwise (drag and drop or File>Open ...).

I'm sure it is an easy fix but beyond my limited macro programming skills.

Thanks for your help

I'm using the version 1.43r

--
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: [hidden email]

http://www.ich.ucl.ac.uk/services_and_facilities/lab_services/confocal_micro
scopy_core_facility/index.html
 
Reply | Threaded
Open this post in threaded view
|

Re: Opening Zeiss LSM files in a macro

jmutterer
Bertrand,

You can do that using the lsm macro extensions provided to the macro
language by the LSM Toolbox plugin. This is how it works:

run("Show LSMToolbox","ext"); // only once in your macro
path="c:\\test.lsm";
Ext.lsmOpen(path);

you can get the LSM Toolbox from:
http://imagejdocu.tudor.lu/doku.php?id=plugin:inputoutput:lsmtoolbox:start

Jerome


On Wed, Mar 24, 2010 at 5:13 PM, Bertrand Vernay <[hidden email]>wrote:

> Dear all
>
> I do not manage to open .lsm5 files when running a macro using the
> open(path) command. The macro works fine with tiff files. ImageJ does open
> the LSM5 file without problem otherwise (drag and drop or File>Open ...).
>
> I'm sure it is an easy fix but beyond my limited macro programming skills.
>
> Thanks for your help
>
> I'm using the version 1.43r
>
> --
> 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: [hidden email]
>
>
> http://www.ich.ucl.ac.uk/services_and_facilities/lab_services/confocal_micro
> scopy_core_facility/index.html
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Opening Zeiss LSM files in a macro

Bertrand Vernay
Thanks Jerome

Problem solved.

Bertrand

//
// This macro batch processes all the lsm files in a folder and any
// subfolders in that folder. In this example, it saves the files
// as TIFF files.

 dir1 = getDirectory("Choose a Directory ");
 dir2 = getDirectory("Choose Destination Directory");  
setBatchMode(true);
 
list = getFileList(dir1);
      for (i=0; i<list.length; i++) {
           path = dir1 + list[i];
        run("Show LSMToolbox","ext"); // only once in your macro
path="c:\\test.lsm"
        Ext.lsmOpen(path);
           saveAs("Tiff", dir2+list[i]);
           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: [hidden email]

http://www.ich.ucl.ac.uk/services_and_facilities/lab_services/confocal_micro
scopy_core_facility/index.html
-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Jerome
Mutterer
Sent: 24 March 2010 17:11
To: [hidden email]
Subject: Re: Opening Zeiss LSM files in a macro

Bertrand,

You can do that using the lsm macro extensions provided to the macro
language by the LSM Toolbox plugin. This is how it works:

run("Show LSMToolbox","ext"); // only once in your macro
path="c:\\test.lsm";
Ext.lsmOpen(path);

you can get the LSM Toolbox from:
http://imagejdocu.tudor.lu/doku.php?id=plugin:inputoutput:lsmtoolbox:start

Jerome


On Wed, Mar 24, 2010 at 5:13 PM, Bertrand Vernay
<[hidden email]>wrote:

> Dear all
>
> I do not manage to open .lsm5 files when running a macro using the
> open(path) command. The macro works fine with tiff files. ImageJ does open
> the LSM5 file without problem otherwise (drag and drop or File>Open ...).
>
> I'm sure it is an easy fix but beyond my limited macro programming skills.
>
> Thanks for your help
>
> I'm using the version 1.43r
>
> --
> 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: [hidden email]
>
>
>
http://www.ich.ucl.ac.uk/services_and_facilities/lab_services/confocal_micro
> scopy_core_facility/index.html
>
>