User defined ROI

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

User defined ROI

Lee Hampson
Hello

I am hoping someone can help me with what I assume is a fairly simple problem!

I have a simple macro that places a ROI on an image using the makeOval command and then extracts the pixel number, mean...etc and performs some calculations.  I'd like to amend it so that the user draws the ROI on the image which is then fed into the macro for the statistics to be extracted as before but unfortunately I don't know how to achieve this and searching on the mailbase has drawn a blank.

Any help would be greatly appreciated!

Lee

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: User defined ROI

vbindokas
Hello Lee,
the command you seek is: [ from
http://imagej.nih.gov/ij/developer/macro/functions.html#S]
*waitForUser(string)*
Halts the macro and displays/string/in a dialog box. The macro proceeds
when the user clicks "OK". UnlikeshowMessage
<http://imagej.nih.gov/ij/developer/macro/functions.html#showMessage>,
the dialog box is not modal, so the user can, for example, create a
selection or adjust the threshold while the dialog is open. To display a
multi-line message, add newline characters ("\n") to/string/. This
function is based on Michael Schmid'sWait_For_User
<http://imagejdocu.tudor.lu/imagej-documentation-wiki/plugins/wait_for_user>plugin.
Example:WaitForUserDemo
<http://imagej.nih.gov/ij/macros/WaitForUserDemo.txt>.


On 10/25/2013 5:51 AM, Lee Hampson wrote:

> Hello
>
> I am hoping someone can help me with what I assume is a fairly simple problem!
>
> I have a simple macro that places a ROI on an image using the makeOval command and then extracts the pixel number, mean...etc and performs some calculations.  I'd like to amend it so that the user draws the ROI on the image which is then fed into the macro for the statistics to be extracted as before but unfortunately I don't know how to achieve this and searching on the mailbase has drawn a blank.
>
> Any help would be greatly appreciated!
>
> Lee
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
__

Vytas Bindokas, Ph.D.
Research Assoc. / Assoc. Prof.,
Director, BSD Light Microscopy Core Facility
Dept Neurobiol Pharmacol Physiol MC0926
947 E 58th Street
The University of Chicago
Chicago IL 60637
Room Abbott 129
773-702-4875

email [hidden email]
web site for LMCF:
http://digital.uchicago.edu/index.html

shipping address (main KCBD site):
V. Bindokas
900 E 57th Street
KCBD room 1250, Microscopy Core
The University of Chicago
Chicago IL 60637


--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: User defined ROI

Lee Hampson
In reply to this post by Lee Hampson
Hi

Thanks for that.  It was this command plus the 'getSelectionBounds' that I was missing.

Regards
Lee

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: User defined ROI

George Patterson
In reply to this post by Lee Hampson
Hi Lee,
The link listed by Vytas will help you a bunch.
Below is a macro we use to measure and fit plot profiles.  It might help to
see another example.  You could probably even edit the appropriate parts
you need for your ROI measurements and calculations.
Alternatively, could you have your users add ROIs to the ROI manager and
edit your macro to select these in sequence?
Best,
George




/*Macro to plot profile a line and fit with a Gaussian function

For this macro, open the image you want to analyze and run the macro.
You will be prompted to pick a directory into which to save the results.
You'll be prompted to choose a new ROI or move an existing ROI (a line,
this macro is assuming).
Once you choose, click the OK button.  You'll see a plot and a fit of the
plot.
The prompt is asking if the fit is OK (OK for your purposes).
If it's not, uncheck the box and move the line to another.  The data from
this fit will not be included in the final text file(see below).
If you feel it necessary, we can make it so you may change the initial
guesses for each fit.
It also asks if you are finished analyzing this image.  If you check this
box, the macro aborts and you can open another image to analyze.
A running mean and sd of the Guassian FWHM is displayed at the bottom.

The "Move your ROI" and "Fitting OK" prompts will repeat until you Cancel
or check the "finished analyzing this image box".

The fit data as well as the plot profile values are saved in the directory
you picked at the beginning.
This is a text file labeled "filename"+_PlotProfileData.txt which you can
open in Excel and perform further analysis if necessary.

Hopefully the column headings will be self explanatory.  The last one "Plot
Profile Values" is the start of the profile values.


*/






//print("\\Clear");

pixelSize=0.130; //�m
Sigma=2;

dir1=getDirectory("Where to store the data?");

imageToPlot=getImageID();
imageTitle=getInfo("image.filename");

PlotProfileData=File.open(dir1+imageTitle+"_PlotProfileData.txt");
print(PlotProfileData,"FWHM"+","+"offset"+","+"amplitude"+","+"Peak
position"+","+"sigma"+","+"R2"+","+"Plot Profile Values");

FWHMArray=newArray();
ROINum=1;

stopAnalysis=false;
while(stopAnalysis==false){

waitForUser("Please make a new ROI or move your present ROI");
profileArray=getProfile();
selectImage(imageToPlot);
run("Plot Profile");
setLocation(100,100);
PlotProfileTitle=getTitle();
Array.getStatistics(profileArray, profileMin, profileMax, profileMean,
profilestdDev);
ProfileValuesToPrint=",";
xPixelArray=newArray(profileArray.length);
for(i=0;i<profileArray.length;i++){
ProfileValuesToPrint=ProfileValuesToPrint+profileArray[i]+",";
xPixelArray[i]=i;//*pixelSize;
}


initialGuesses=newArray(profileMin,profileMax,(xPixelArray.length/2),Sigma);
 //offset, amplitude,x position,sigma
x=xPixelArray;
y=profileArray;
//Fit.showDialog;
Fit.doFit("Gaussian",x,y,initialGuesses);
Fit.plot;
//run("Save", "save="+dir1+"Plot_profile_fit.txt");
a=Fit.p(0);//offset
b=Fit.p(1);//Amplitude
c=Fit.p(2);//Peak position
d=Fit.p(3);//Sigma
R2=Fit.rSquared;
setLocation(100,500);

ProfileFitTitle=getTitle();
FWHM=2.35482*d;   //FWHM=2(sqrt(2*ln2))*sigma

FWHMArray=appendToArray(FWHM,FWHMArray);
Array.getStatistics(FWHMArray,FWHMMin,FWHMMax,FWHMMean,FWHMSD);


Dialog.create("Fits Ok, continue?");
Dialog.addCheckbox("This fit OK?",true);
Dialog.addMessage("");
Dialog.addCheckbox("Finished analyzing this image?",false);
Dialog.addMessage("");
Dialog.addMessage("FWHM measurements thus far: "+FWHMMean+"±"+FWHMSD+"
 n="+ROINum);
Dialog.show();

FitOK=Dialog.getCheckbox();
stopAnalysis=Dialog.getCheckbox();

if(FitOK==true){
print(PlotProfileData,FWHM+","+a+","+b+","+c+","+d+","+R2+","+ProfileValuesToPrint);
ROINum=ROINum+1;
}
selectWindow(PlotProfileTitle);
close();
selectWindow(ProfileFitTitle);
close();

if(stopAnalysis==true)
File.close(PlotProfileData);
}


function appendToArray(value, array) {
temparray=newArray(lengthOf(array)+1);
for(i=0;i<lengthOf(array);i++){
temparray[i]=array[i];
}
temparray[lengthOf(temparray)-1]=value;
array=temparray;
return array;
}



On Fri, Oct 25, 2013 at 6:51 AM, Lee Hampson <[hidden email]> wrote:

> Hello
>
> I am hoping someone can help me with what I assume is a fairly simple
> problem!
>
> I have a simple macro that places a ROI on an image using the makeOval
> command and then extracts the pixel number, mean...etc and performs some
> calculations.  I'd like to amend it so that the user draws the ROI on the
> image which is then fed into the macro for the statistics to be extracted
> as before but unfortunately I don't know how to achieve this and searching
> on the mailbase has drawn a blank.
>
> Any help would be greatly appreciated!
>
> Lee
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html