dialog box

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

dialog box

Michael Doube-2
Dear List

I have a macro that measures length and density within 2-300 manually
placed ROIs in a stack of images.  This part works fine.

I'd like to have a dialog box open that the macro looks at to get data
about the specimen that the images are of - whether the surface was
milled or polished and the orientation of the specimen.  I only have to
set this data at the beginning of a set of measurements, after opening
the image stack.  I tried putting a dialog in the macro, which works,
only it asks me to set the variables every time I take a measurement.

How can I make a dialog that I can set at the beginning, that my macro
will refer to each time it is run?  At the moment I have to edit the
macro manually each time I change images.  Not too onerous, but inelegant.

I'm OK at macro writing but haven't written a plugin yet.

The measure and dialog macros follow.

Thanks,

Mike

----------------SpecimenInfo.txt---------------
Dialog.create("Specimen Information");
Dialog.addChoice("Finish", newArray("Milled", "Polished"));
Dialog.addChoice("Lateral is to the", newArray("Left", "Right"));
Dialog.show();
finish = Dialog.getChoice();
lateral = Dialog.getChoice();
--------------------------------------------------
----------------CalcifiedCartilage.txt-------------

macro "Calcified Cartilage [q]" {
    requires("1.34h");                          
    var bmmd;
    var fraction;

//set the side that lateral is on, either left (1) or right (0)
lateral = 0;

//get the pixel information from inside the ROI  
 getRawStatistics(count, mean, min, max, std, histogram);
 row = nResults;

//get the number of image fields in the stack from ImageJ
fields = nSlices();
 
//use this line if dealing with a stacked series of images
name=getMetadata();

//use this line if dealing with single images
//    name = getTitle();

//  The following section is to speed up my labelling
    horse = substring(name, 0, 2);
   leg = substring(name, 2, 3);
   section = substring(name, 3, 4);

//use these lines to manually control the threshold
lower=1;
upper=255;

    for (k=0; k<lower; k++) {
        background = background + histogram[k];
        fraction = (count - background) / count;
        setResult("Vfc ", row, fraction);        
    }
 
    for(j=lower; j<upper; j++) {
        cumulative = cumulative + histogram[j];
         av = av + j * histogram[j];
        bmmd = av / cumulative;
        setResult("Mean Matrix", row, bmmd);
    }
 
modep=0;
    mode = 0;
    for (p=lower; p<upper; p++) {
 
        if (mode < histogram[p]) {
        mode = histogram[p];
        setResult("Mode", row, p);
        modep = p;
    }
    }

    setResult("Mean ROI ", row, mean);
 
//get the coordinates of the ends of the straight line selection
getLine(a,b,c,d,w);

//calculate line length - go pythagoras
thickness=sqrt((a-c)*(a-c)+(b-d)*(b-d));

//Calculate relative position from left, lateral is always left, image
sequences start on left
ni = getSliceNumber();
if (lateral == 1)
    pos = ni / fields;
else if (lateral == 0)
    pos = (-1)*(ni / fields-1);

//the next line prints results in a log window
print(horse, " \t", leg, "\t", section, "\t", "p","\t", modep, " \t",
mean, " \t", bmmd, " \t", fraction, "\t", thickness, "\t", pos,"
\n");              
                }
 
    setSlice(n);

}
-----------------------------------

--
Michael Doube  BPhil BVSc MRCVS
MPhil / PhD Student
Dental Institute
Barts and The London School of Medicine and Dentistry
Queen Mary, University of London
New Rd
London  E1 1BB
United Kingdom

Phone +44 (0)20 7377 7000 ext 2681
Reply | Threaded
Open this post in threaded view
|

Re: dialog box

Gabriel Landini
On Wednesday 09 November 2005 10:21, Michael Doube wrote:
> I'd like to have a dialog box open that the macro looks at to get data
> about the specimen that the images are of - whether the surface was
> milled or polished and the orientation of the specimen.


Not what you are asking for, but it may help:
Could you embed the data in the image and get it back in the macro with
getMetadata() or something along the lines?

Cheers,
G.
Reply | Threaded
Open this post in threaded view
|

AW: dialog box

Kirmse Robert
In reply to this post by Michael Doube-2
You can also try to use global variables defined outside of functions or
macro declarations.
They will last, even if the macro is finished.
You can then just use an if statement or something else to check if you
already set a value or not.
If not bring up the dialog and so on.

That worked fine for me (even if global variables aren´t considered good
programming style sometimes)

Cheers
robert

-----Ursprüngliche Nachricht-----
Von: ImageJ Interest Group [mailto:[hidden email]] Im Auftrag von
Michael Doube
Gesendet: Mittwoch, 9. November 2005 11:22
An: [hidden email]
Betreff: dialog box

Dear List

I have a macro that measures length and density within 2-300 manually placed
ROIs in a stack of images.  This part works fine.

I'd like to have a dialog box open that the macro looks at to get data about
the specimen that the images are of - whether the surface was milled or
polished and the orientation of the specimen.  I only have to set this data
at the beginning of a set of measurements, after opening the image stack.  I
tried putting a dialog in the macro, which works, only it asks me to set the
variables every time I take a measurement.

How can I make a dialog that I can set at the beginning, that my macro will
refer to each time it is run?  At the moment I have to edit the macro
manually each time I change images.  Not too onerous, but inelegant.

I'm OK at macro writing but haven't written a plugin yet.

The measure and dialog macros follow.

Thanks,

Mike

----------------SpecimenInfo.txt---------------
Dialog.create("Specimen Information");
Dialog.addChoice("Finish", newArray("Milled", "Polished"));
Dialog.addChoice("Lateral is to the", newArray("Left", "Right"));
Dialog.show(); finish = Dialog.getChoice(); lateral = Dialog.getChoice();
--------------------------------------------------
----------------CalcifiedCartilage.txt-------------

macro "Calcified Cartilage [q]" {
    requires("1.34h");                          
    var bmmd;
    var fraction;

//set the side that lateral is on, either left (1) or right (0) lateral = 0;

//get the pixel information from inside the ROI  
 getRawStatistics(count, mean, min, max, std, histogram);  row = nResults;

//get the number of image fields in the stack from ImageJ fields =
nSlices();
 
//use this line if dealing with a stacked series of images
name=getMetadata();

//use this line if dealing with single images
//    name = getTitle();

//  The following section is to speed up my labelling
    horse = substring(name, 0, 2);
   leg = substring(name, 2, 3);
   section = substring(name, 3, 4);

//use these lines to manually control the threshold lower=1; upper=255;

    for (k=0; k<lower; k++) {
        background = background + histogram[k];
        fraction = (count - background) / count;
        setResult("Vfc ", row, fraction);        
    }
 
    for(j=lower; j<upper; j++) {
        cumulative = cumulative + histogram[j];
         av = av + j * histogram[j];
        bmmd = av / cumulative;
        setResult("Mean Matrix", row, bmmd);
    }
 
modep=0;
    mode = 0;
    for (p=lower; p<upper; p++) {
 
        if (mode < histogram[p]) {
        mode = histogram[p];
        setResult("Mode", row, p);
        modep = p;
    }
    }

    setResult("Mean ROI ", row, mean);
 
//get the coordinates of the ends of the straight line selection
getLine(a,b,c,d,w);

//calculate line length - go pythagoras
thickness=sqrt((a-c)*(a-c)+(b-d)*(b-d));

//Calculate relative position from left, lateral is always left, image
sequences start on left ni = getSliceNumber(); if (lateral == 1)
    pos = ni / fields;
else if (lateral == 0)
    pos = (-1)*(ni / fields-1);

//the next line prints results in a log window print(horse, " \t", leg,
"\t", section, "\t", "p","\t", modep, " \t", mean, " \t", bmmd, " \t",
fraction, "\t", thickness, "\t", pos,"
\n");              
                }
 
    setSlice(n);

}
-----------------------------------

--
Michael Doube  BPhil BVSc MRCVS
MPhil / PhD Student
Dental Institute
Barts and The London School of Medicine and Dentistry Queen Mary, University
of London New Rd London  E1 1BB United Kingdom

Phone +44 (0)20 7377 7000 ext 2681
Reply | Threaded
Open this post in threaded view
|

Re: dialog box

Michael Doube-2
In reply to this post by Gabriel Landini
Thanks for the suggestion Gabriel

>Could you embed the data in the image
>  
>

I wrote a script that can do this.  However, it won't run if included
after a line that automates image sequence opening, only by itself.

How can I make all of this macro work in one go - for example after a
key press?  It seems to stop after the first line.

Thanks

Mike

-----------CartilageOpener.txt-------------
//import image sequence
run("Image Sequence...", "number=999 starting=1 increment=1 scale=100
file=tif");

//Make a dialog box
Dialog.create("Specimen Information");
Dialog.addCheckbox("Lateral to left (uncheck if right)", true);
Dialog.addCheckbox("Surface milled (uncheck if polished)", true);
Dialog.show();
left = Dialog.getCheckbox();
milled = Dialog.getCheckbox();

//do for all slices
if (nSlices>1)
    n = getSliceNumber();
    for (i=1; i<=nSlices; i++) {
    setSlice(i);

//set logical values
if (left==true)
    left = 1;
else
    left = 0;

if (milled==true)
    milled = 1;
else
    milled = 0;

//append to metadata string
image = getMetadata();
setMetadata(left+""+milled+""+image);

 setSlice(n);
}



--
Michael Doube  BPhil BVSc MRCVS
MPhil / PhD Student
Dental Institute
Barts and The London School of Medicine and Dentistry
Queen Mary, University of London
New Rd
London  E1 1BB
United Kingdom

Phone +44 (0)20 7377 7000 ext 2681
Reply | Threaded
Open this post in threaded view
|

Re: dialog box

Wayne Rasband
In reply to this post by Michael Doube-2
> I have a macro that measures length and density within 2-300
> manually placed ROIs in a stack of images.  This part works
> fine.
>
> I'd like to have a dialog box open that the macro looks at
> to get data about the specimen that the images are of -
> whether the surface was milled or polished and the
> orientation of the specimen.  I only have to set this data
> at the beginning of a set of measurements, after opening the
> image stack.  I tried putting a dialog in the macro, which
> works, only it asks me to set the variables every time I
> take a measurement.
>
> How can I make a dialog that I can set at the beginning,
> that my macro will refer to each time it is run?  At the
> moment I have to edit the macro manually each time I change
> images.  Not too onerous, but inelegant.

Create a macro set consisting of two macros, one that displays the  
dialog and another that does the analysis. The dialog macro sets global  
variables that are accessed by the macro that does the analysis. The  
macro set would look something like this:

//----------------------
CalcifiedCartilageMacros.txt---------------------
var finish;
var lateral;

macro "Show Dialog..." {
   Dialog.create("Specimen Information");
   Dialog.addChoice("Finish", newArray("Milled", "Polished"));
   Dialog.addChoice("Lateral is to the", newArray("Left", "Right"));
   Dialog.show();
   finish = Dialog.getChoice();
   lateral = Dialog.getChoice();
}

macro "Calcified Cartilage [q]" {
   // get statistics
   if (lateral == 1)
     pos = ni / fields;
   else if (lateral == 0)
     pos = (-1)*(ni / fields-1);
}

//---------------------------------------------------------

More information about macro sets can be found at:

     http://rsb.info.nih.gov/ij/developer/macro/macros.html#sets

-wayne


> I'm OK at macro writing but haven't written a plugin yet.
>
> The measure and dialog macros follow.
>
> Thanks,
>
> Mike
>
> ----------------SpecimenInfo.txt---------------
> Dialog.create("Specimen Information");
> Dialog.addChoice("Finish", newArray("Milled", "Polished"));
> Dialog.addChoice("Lateral is to the", newArray("Left", "Right"));
> Dialog.show();
> finish = Dialog.getChoice();
> lateral = Dialog.getChoice();
> --------------------------------------------------
> ----------------CalcifiedCartilage.txt-------------
>
> macro "Calcified Cartilage [q]" {
>     requires("1.34h");                         
>     var bmmd;
>     var fraction;
>
> //set the side that lateral is on, either left (1) or right (0)
> lateral = 0;
>
> //get the pixel information from inside the ROI  
>  getRawStatistics(count, mean, min, max, std, histogram);
>  row = nResults;
>
> //get the number of image fields in the stack from ImageJ
> fields = nSlices();
>  
> //use this line if dealing with a stacked series of images
> name=getMetadata();
>
> //use this line if dealing with single images
> //    name = getTitle();
>
> //  The following section is to speed up my labelling
>     horse = substring(name, 0, 2);
>    leg = substring(name, 2, 3);
>    section = substring(name, 3, 4);
>
> //use these lines to manually control the threshold
> lower=1;
> upper=255;
>
>     for (k=0; k<lower; k++) {
>         background = background + histogram[k];
>         fraction = (count - background) / count;
>         setResult("Vfc ", row, fraction);       
>     }
>  
>     for(j=lower; j<upper; j++) {
>         cumulative = cumulative + histogram[j];
>          av = av + j * histogram[j];
>         bmmd = av / cumulative;
>         setResult("Mean Matrix", row, bmmd);
>     }
>  
> modep=0;
>     mode = 0;
>     for (p=lower; p<upper; p++) {
>  
>         if (mode < histogram[p]) {
>         mode = histogram[p];
>         setResult("Mode", row, p);
>         modep = p;
>     }
>     }
>
>     setResult("Mean ROI ", row, mean);
>  
> //get the coordinates of the ends of the straight line selection
> getLine(a,b,c,d,w);
>
> //calculate line length - go pythagoras
> thickness=sqrt((a-c)*(a-c)+(b-d)*(b-d));
>
> //Calculate relative position from left, lateral is always left, image
> sequences start on left
> ni = getSliceNumber();
> if (lateral == 1)
>     pos = ni / fields;
> else if (lateral == 0)
>     pos = (-1)*(ni / fields-1);
>
> //the next line prints results in a log window
> print(horse, " \t", leg, "\t", section, "\t", "p","\t", modep, " \t",
> mean, " \t", bmmd, " \t", fraction, "\t", thickness, "\t", pos,"
> \n");              
>                 }
>  
>     setSlice(n);
>
> }
> -----------------------------------
>
> --
> Michael Doube  BPhil BVSc MRCVS
> MPhil / PhD Student
> Dental Institute
> Barts and The London School of Medicine and Dentistry
> Queen Mary, University of London
> New Rd
> London  E1 1BB
> United Kingdom
>
> Phone +44 (0)20 7377 7000 ext 2681