Hi,
For my experiment, I am taking images every few minutes with each image having its own set of of metamorph ROIs. My metamorph journal saves the images as a stack and each image has its own metamorph regions (.rgn) file (example: 6 images = 1 stack plus six individual .rgn files corresponding to each image in the stack). I am using the metamorph nd and ROI files importer (nd stack builder) plugin to import the regions as ROIs. I would like to write a macro code that will allow me to import each .rgn metamorph file, convert those ROIs to overlays, and then save the new image. I can get every part other but haven't been able to automate the plugin part that imports the ROIs. Currently, I have to select each new region that I want to import. This ends up being very tedious if stacks are bigger than 20 slices. The code that I'm using currently is below, with annotations. setBatchMode(true); waitForUser("Choose the directory to save string of images"); dir=getDirectory("Choose a Directory"); selectWindow("Stack.stk"); run("Duplicate...", "title=Duplicate_stack duplicate range=1-100"); selectWindow("Duplicate_stack"); frames=nSlices(); for (n=1; n<=frames; n++) { setSlice(n); title=n; run("Duplicate...", "title=Duplicate"); selectWindow("Duplicate"); run("Metamorph ROI"); //Here it opens up a dialog box for me to pick which .rgn file I want to import count=roiManager("count"); for (i=1; i<=count; i++) { roi=i-1; roiManager("Select", roi); run("Add Selection..."); } selectWindow("Duplicate"); saveAs("Tiff", dir+title); roiManager("Reset"); selectWindow("Duplicate_stack"); } setBatchMode(false); Here is code that I've tried, but it still opens the dialog box instead of just selecting the .rgn based on the array setBatchMode(true); waitForUser("Choose the directory to save string of images"); dir=getDirectory("Choose a Directory"); waitForUser("Choose the regions folder"); rgn=getDirectory("Choose a Directory"); list=getFileList(rgn); selectWindow("Stack.stk"); run("Duplicate...", "title=Duplicate_stack duplicate range=1-100"); selectWindow("Duplicate_stack"); frames=nSlices(); for (n=1; n<=frames; n++) { setSlice(n); title=n; run("Duplicate...", "title=Duplicate"); selectWindow("Duplicate"); i=n-1; region=list[i] run("Metamorph ROI", rgn+region); //Opens up a dialog box for me to pick which .rgn file I want to import count=roiManager("count"); for (i=1; i<=count; i++) { roi=i-1; roiManager("Select", roi); run("Add Selection..."); } selectWindow("Duplicate"); saveAs("Tiff", dir+title); roiManager("Reset"); selectWindow("Duplicate_stack"); } setBatchMode(false); Thanks so much for the help! Kristen -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
On 10/24/2013 05:42 PM, Kristen Lee Witte wrote:
> I can get every part other but haven't been able to automate the > plugin part that imports the ROIs. > "Metamorph ROI" was showing the dialog box, because you were not overwriting the variable name it expected. To easiest way to find out the name of the variables, is to use the Macro recorder i.e. Plugins > Macros > Record... When I ran the "Metamorph ROI" plugin and selected a MetaMorph region, I got this new line in the Recorder: run("Metamorph ROI", "open=[/tmp/rois/bleach pattern for slide.rgn]"); This tells me I need to overwrite the "open" variable. The square brackets are ImageJ's way of making sure spaces in the directory or filename do not create problems, so we should keep those. It looks like you were also missing a semicolon at the end of region=list[i]. Below is a summary of the 2 changes. ------------------------------------------------------------------------ diff -c /tmp/m2.txt /tmp/m3.txt --- /tmp/m2.txt 2013-10-26 17:02:30.704000000 -0400 +++ /tmp/m3.txt 2013-10-26 17:01:40.256000000 -0400 @@ -15,8 +15,8 @@ run("Duplicate...", "title=Duplicate"); selectWindow("Duplicate"); i=n-1; - region=list[i] - run("Metamorph ROI", rgn+region); //Opens up a dialog box for me to pick which .rgn file I want to import + region=list[i]; + run("Metamorph ROI", "open=["+rgn+region+"]"); count=roiManager("count"); for (i=1; i<=count; i++) { roi=i-1; Diff finished. Sat Oct 26 17:02:38 2013 ------------------------------------------------------------------------ The full modified macro file is at the end of this e-mail. > Kristen Pariksheet ------------------------------------------------------------------------ setBatchMode(true); waitForUser("Choose the directory to save string of images"); dir=getDirectory("Choose a Directory"); waitForUser("Choose the regions folder"); rgn=getDirectory("Choose a Directory"); list=getFileList(rgn); selectWindow("Stack.stk"); run("Duplicate...", "title=Duplicate_stack duplicate range=1-100"); selectWindow("Duplicate_stack"); frames=nSlices(); for (n=1; n<=frames; n++) { setSlice(n); title=n; run("Duplicate...", "title=Duplicate"); selectWindow("Duplicate"); i=n-1; region=list[i]; run("Metamorph ROI", "open=["+rgn+region+"]"); count=roiManager("count"); for (i=1; i<=count; i++) { roi=i-1; roiManager("Select", roi); run("Add Selection..."); } selectWindow("Duplicate"); saveAs("Tiff", dir+title); roiManager("Reset"); selectWindow("Duplicate_stack"); } setBatchMode(false); ------------------------------------------------------------------------ -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |