Posted by
Kirmse Robert on
Nov 09, 2005; 1:14pm
URL: http://imagej.273.s1.nabble.com/dialog-box-tp3704509p3704513.html
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