Posted by
Kristen Lee Witte on
Oct 24, 2013; 9:42pm
URL: http://imagej.273.s1.nabble.com/Import-Metamorph-ROI-tp5005310.html
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