Hello,
Im currently writing my first real macro which runs fine in normal mode but not batch mode. The macro is pasted below. Essentially it first asks whether there is a brightfield image in the stack or not. Based on the number of channels in the stack and the response to the aforementioned question it runs one of four blocks of code. If I open multiple 3 or 4 channel stacks lacking a brightfield image and i run this macro and uncheck the tick box at the start and push ok it works fine. However, if i add setBatchMode(true); at the top of the macro it fails. It makes an attempt at the first stack but never gets beyond this generally failing with stack slicer saying it needs a stack. I have a suspicion the problem lies somewhere in one of the close(); statements closing one of my stacks before it has been processed when in batch mode. Have I done something wrong??? Im learning as i write basically. I also had to remove all print functions with // otherwise if the log window was closed and i ran the code it would fail every time. However, if the log window was open it did not fail. Not sure why this is. I did try and write something simple to highlight the problem but i cant figure it out ! Any help would be appreciated. Thanks Mike setBatchMode(true); Dialog.create("Mikes macro"); Dialog.addCheckbox("BF image in stack?", true) Dialog.show(); BFimage = Dialog.getCheckbox(); dir = getDirectory("Choose a Directory"); ids=newArray(nImages); for (i=0;i<nImages;i++) { selectImage(i+1); title = getTitle; //print(title); ids[i]=getImageID; getDimensions(w, h, channels, slices, frames); if (BFimage==false && channels==3) { //print("3 fluorescent channels no BF"); run("Duplicate...", "duplicate channels=1-3"); rename(title+"_"+i); newtitle = getTitle; run("8-bit"); run("Z Project...", "projection=[Max Intensity]"); saveAs("tiff", dir+newtitle+"_MAXprj.tif"); run("Image Sequence... ", "format=TIFF start=0 digits=2 save=dir"); MAX = getImageID(); run("Stack Slicer", "split_channels keep_original stack_order=XYCZT"); selectImage(MAX); run("RGB Color"); saveAs("tiff", dir+newtitle+"_MAXprj_RGB.tif"); run("Images to Stack", "name=[Stack] title=[] use"); run("Make Montage...", "columns=4 rows=1 scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage.tif"); close(); close(); close(); close(); } else if (BFimage==false && channels==4) { //print("4 fluorescent channels no BF"); run("Duplicate...", "duplicate channels=1-4"); rename(title+"_"+i); newtitle = getTitle; run("8-bit"); run("Z Project...", "projection=[Max Intensity]"); MAX = getImageID(); saveAs("tiff", dir+newtitle+"_MAXprj.tif"); run("Image Sequence... ", "format=TIFF start=0 digits=2 save=dir"); run("Stack Slicer", "split_channels keep_original stack_order=XYCZT"); selectImage(MAX); run("Make Substack...", "channels=1,3,4"); substack1 = getImageID(); run("RGB Color"); saveAs("tiff", dir+newtitle+"_MAXprj_RGBch1-3-4.tif"); selectImage(substack1); close(); selectImage(MAX); run("Make Substack...", "channels=2,3,4"); substack2 = getImageID(); run("RGB Color"); saveAs("tiff", dir+newtitle+"_MAXprj_RGBch2-3-4.tif"); selectImage(substack2); close(); run("Images to Stack", "name=[Stack] title=[] use"); monty = getImageID(); run("Make Montage...", "columns=6 rows=1 scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage1.tif"); close(); selectImage(monty); run("Make Substack...", "slices=1-5"); substack3 = getImageID(); run("Make Montage...", "columns=5 rows=1 scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage2.tif"); close(); selectImage(substack3); close(); selectImage(monty); run("Make Substack...", "slices=1,2,3,4,6"); substack3 = getImageID(); run("Make Montage...", "columns=5 rows=1 scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage3.tif"); close(); selectImage(substack3); close(); selectImage(MAX); close(); selectImage(monty); close(); close(); } else if (BFimage==true && channels==4) { //print("3 fluorescent channels and one BF image"); run("Duplicate...", "duplicate channels=1-4"); rename(title+"_"+i); newtitle = getTitle; run("8-bit"); run("Z Project...", "projection=[Max Intensity]"); saveAs("tiff", dir+newtitle+"_MAXprj.tif"); run("Image Sequence... ", "format=TIFF start=0 digits=2 save=dir"); MAX = getImageID(); run("Make Substack...", "channels=1-3"); fchanMAX = getImageID(); run("Stack Slicer", "split_channels keep_original stack_order=XYCZT"); selectImage(fchanMAX); run("RGB Color"); saveAs("tiff", dir+newtitle+"_MAXprj_RGB.tif"); selectImage(MAX); run("Make Substack...", "channels=4"); run("Images to Stack", "name=[Stack] title=[] use"); run("Colors...", "foreground=white background=white"); run("Make Montage...", "columns=5 rows=1 scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage.tif"); close(); close(); close(); close(); close(); } else if (BFimage==true && channels==5) { //print("4 fluorescent channels and one BF image"); run("Duplicate...", "duplicate channels=1-5"); rename(title+"_"+i); newtitle = getTitle; run("8-bit"); Im1 = getImageID(); run("Z Project...", "projection=[Max Intensity]"); MAX = getImageID(); saveAs("tiff", dir+newtitle+"_MAXprj.tif"); run("Image Sequence... ", "format=TIFF start=0 digits=2 save=dir"); selectImage(MAX); run("Make Substack...", "channels=1-4"); substack3 = getImageID(); run("Stack Slicer", "split_channels keep_original stack_order=XYCZT"); selectImage(MAX); run("Make Substack...", "channels=1,3,4"); substack1 = getImageID(); run("RGB Color"); saveAs("tiff", dir+newtitle+"_MAXprj_RGBch1-3-4.tif"); selectImage(substack1); close(); selectImage(MAX); run("Make Substack...", "channels=2,3,4"); substack2 = getImageID(); run("RGB Color"); saveAs("tiff", dir+newtitle+"_MAXprj_RGBch2-3-4.tif"); selectImage(substack2); close(); selectImage(MAX); run("Duplicate...", "duplicate channels=5"); run("Images to Stack", "name=[Stack] title=[] use"); monty = getImageID(); run("Make Montage...", "columns=7 rows=1 scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage1.tif"); close(); selectImage(monty); run("Make Substack...", "slices=1,2,3,4,5,7"); substack3 = getImageID(); run("Make Montage...", "columns=6 rows=1 scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage2.tif"); close(); selectImage(substack3); close(); selectImage(monty); run("Make Substack...", "slices=1,2,3,4,6,7"); substack3 = getImageID(); run("Make Montage...", "columns=6 rows=1 scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage3.tif"); //selectImage(substack3); close(); //selectImage(Im1); close(); //selectImage(MAX); close(); //selectImage(monty); close(); close(); close(); }} -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
apologies for repeating, but in my mail program the macro text is not displayed properly. I have repasted this below. I hope it displays properly this time.
//setBatchMode(true); Dialog.create("Mikes macro"); Dialog.addCheckbox("BF image in stack?", true) Dialog.show(); BFimage = Dialog.getCheckbox(); dir = getDirectory("Choose a Directory"); ids=newArray(nImages); for (i=0;i<nImages;i++) { selectImage(i+1); title = getTitle; //print(title); ids[i]=getImageID; getDimensions(w, h, channels, slices, frames); if (BFimage==false && channels==3) { //print("3 fluorescent channels no BF"); run("Duplicate...", "duplicate channels=1-3"); rename(title+"_"+i); newtitle = getTitle; run("8-bit"); run("Z Project...", "projection=[Max Intensity]"); saveAs("tiff", dir+newtitle+"_MAXprj.tif"); run("Image Sequence... ", "format=TIFF start=0 digits=2 save=dir"); MAX = getImageID(); run("Stack Slicer", "split_channels keep_original stack_order=XYCZT"); selectImage(MAX); run("RGB Color"); saveAs("tiff", dir+newtitle+"_MAXprj_RGB.tif"); run("Images to Stack", "name=[Stack] title=[] use"); run("Make Montage...", "columns=4 rows=1 scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage.tif"); close(); close(); close(); close(); } else if (BFimage==false && channels==4) { //print("4 fluorescent channels no BF"); run("Duplicate...", "duplicate channels=1-4"); rename(title+"_"+i); newtitle = getTitle; run("8-bit"); run("Z Project...", "projection=[Max Intensity]"); MAX = getImageID(); saveAs("tiff", dir+newtitle+"_MAXprj.tif"); run("Image Sequence... ", "format=TIFF start=0 digits=2 save=dir"); run("Stack Slicer", "split_channels keep_original stack_order=XYCZT"); selectImage(MAX); run("Make Substack...", "channels=1,3,4"); substack1 = getImageID(); run("RGB Color"); saveAs("tiff", dir+newtitle+"_MAXprj_RGBch1-3-4.tif"); selectImage(substack1); close(); selectImage(MAX); run("Make Substack...", "channels=2,3,4"); substack2 = getImageID(); run("RGB Color"); saveAs("tiff", dir+newtitle+"_MAXprj_RGBch2-3-4.tif"); selectImage(substack2); close(); run("Images to Stack", "name=[Stack] title=[] use"); monty = getImageID(); run("Make Montage...", "columns=6 rows=1 scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage1.tif"); close(); selectImage(monty); run("Make Substack...", "slices=1-5"); substack3 = getImageID(); run("Make Montage...", "columns=5 rows=1 scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage2.tif"); close(); selectImage(substack3); close(); selectImage(monty); run("Make Substack...", "slices=1,2,3,4,6"); substack3 = getImageID(); run("Make Montage...", "columns=5 rows=1 scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage3.tif"); close(); selectImage(substack3); close(); selectImage(MAX); close(); selectImage(monty); close(); close(); } else if (BFimage==true && channels==4) { //print("3 fluorescent channels and one BF image"); run("Duplicate...", "duplicate channels=1-4"); rename(title+"_"+i); newtitle = getTitle; run("8-bit"); run("Z Project...", "projection=[Max Intensity]"); saveAs("tiff", dir+newtitle+"_MAXprj.tif"); run("Image Sequence... ", "format=TIFF start=0 digits=2 save=dir"); MAX = getImageID(); run("Make Substack...", "channels=1-3"); fchanMAX = getImageID(); run("Stack Slicer", "split_channels keep_original stack_order=XYCZT"); selectImage(fchanMAX); run("RGB Color"); saveAs("tiff", dir+newtitle+"_MAXprj_RGB.tif"); selectImage(MAX); run("Make Substack...", "channels=4"); run("Images to Stack", "name=[Stack] title=[] use"); run("Colors...", "foreground=white background=white"); run("Make Montage...", "columns=5 rows=1 scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage.tif"); close(); close(); close(); close(); close(); } else if (BFimage==true && channels==5) { //print("4 fluorescent channels and one BF image"); run("Duplicate...", "duplicate channels=1-5"); rename(title+"_"+i); newtitle = getTitle; run("8-bit"); Im1 = getImageID(); run("Z Project...", "projection=[Max Intensity]"); MAX = getImageID(); saveAs("tiff", dir+newtitle+"_MAXprj.tif"); run("Image Sequence... ", "format=TIFF start=0 digits=2 save=dir"); selectImage(MAX); run("Make Substack...", "channels=1-4"); substack3 = getImageID(); run("Stack Slicer", "split_channels keep_original stack_order=XYCZT"); selectImage(MAX); run("Make Substack...", "channels=1,3,4"); substack1 = getImageID(); run("RGB Color"); saveAs("tiff", dir+newtitle+"_MAXprj_RGBch1-3-4.tif"); selectImage(substack1); close(); selectImage(MAX); run("Make Substack...", "channels=2,3,4"); substack2 = getImageID(); run("RGB Color"); saveAs("tiff", dir+newtitle+"_MAXprj_RGBch2-3-4.tif"); selectImage(substack2); close(); selectImage(MAX); run("Duplicate...", "duplicate channels=5"); run("Images to Stack", "name=[Stack] title=[] use"); monty = getImageID(); run("Make Montage...", "columns=7 rows=1 scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage1.tif"); close(); selectImage(monty); run("Make Substack...", "slices=1,2,3,4,5,7"); substack3 = getImageID(); run("Make Montage...", "columns=6 rows=1 scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage2.tif"); close(); selectImage(substack3); close(); selectImage(monty); run("Make Substack...", "slices=1,2,3,4,6,7"); substack3 = getImageID(); run("Make Montage...", "columns=6 rows=1 scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage3.tif"); //selectImage(substack3); close(); //selectImage(Im1); close(); //selectImage(MAX); close(); //selectImage(monty); close(); close(); close(); }} > Date: Tue, 16 Jul 2013 16:54:36 +0000 > From: [hidden email] > Subject: macro batch mode problem > To: [hidden email] > > Hello, > Im currently writing my first real macro which runs fine in normal mode but not batch mode. The macro is pasted below. Essentially it first asks whether there is a brightfield image in the stack or not. Based on the number of channels in the stack and the response to the aforementioned question it runs one of four blocks of code. If I open multiple 3 or 4 channel stacks lacking a brightfield image and i run this macro and uncheck the tick box at the start and push ok it works fine. However, if i add setBatchMode(true); at the top of the macro it fails. It makes an attempt at the first stack but never gets beyond this generally failing with stack slicer saying it needs a stack. I have a suspicion the problem lies somewhere in one of the close(); statements closing one of my stacks before it has been processed when in batch mode. Have I done something wrong??? Im learning as i write basically. > I also had to remove all print functions with // otherwise if the log window was closed and i ran the code it would fail every time. However, if the log window was open it did not fail. Not sure why this is. > I did try and write something simple to highlight the problem but i cant figure it out ! > Any help would be appreciated. > Thanks > Mike > > > setBatchMode(true); > Dialog.create("Mikes macro"); Dialog.addCheckbox("BF image in stack?", true) Dialog.show(); BFimage = Dialog.getCheckbox(); dir = getDirectory("Choose a Directory"); > ids=newArray(nImages); for (i=0;i<nImages;i++) { selectImage(i+1); title = getTitle; //print(title); ids[i]=getImageID; getDimensions(w, h, channels, slices, frames); > if (BFimage==false && channels==3) { //print("3 fluorescent channels no BF"); run("Duplicate...", "duplicate channels=1-3"); rename(title+"_"+i); newtitle = getTitle; run("8-bit"); run("Z Project...", "projection=[Max Intensity]"); saveAs("tiff", dir+newtitle+"_MAXprj.tif"); run("Image Sequence... ", "format=TIFF start=0 digits=2 save=dir"); MAX = getImageID(); run("Stack Slicer", "split_channels keep_original stack_order=XYCZT"); selectImage(MAX); run("RGB Color"); saveAs("tiff", dir+newtitle+"_MAXprj_RGB.tif"); run("Images to Stack", "name=[Stack] title=[] use"); run("Make Montage...", "columns=4 rows=1 scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage.tif"); close(); close(); close(); close(); } > else if (BFimage==false && channels==4) { //print("4 fluorescent channels no BF"); run("Duplicate...", "duplicate channels=1-4"); rename(title+"_"+i); newtitle = getTitle; run("8-bit"); run("Z Project...", "projection=[Max Intensity]"); MAX = getImageID(); saveAs("tiff", dir+newtitle+"_MAXprj.tif"); run("Image Sequence... ", "format=TIFF start=0 digits=2 save=dir"); run("Stack Slicer", "split_channels keep_original stack_order=XYCZT"); selectImage(MAX); run("Make Substack...", "channels=1,3,4"); substack1 = getImageID(); run("RGB Color"); saveAs("tiff", dir+newtitle+"_MAXprj_RGBch1-3-4.tif"); selectImage(substack1); close(); selectImage(MAX); run("Make Substack...", "channels=2,3,4"); substack2 = getImageID(); run("RGB Color"); saveAs("tiff", dir+newtitle+"_MAXprj_RGBch2-3-4.tif"); selectImage(substack2); close(); run("Images to Stack", "name=[Stack] title=[] use"); monty = getImageID(); run("Make Montage...", "columns=6 rows=1 scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage1.tif"); close(); selectImage(monty); run("Make Substack...", "slices=1-5"); substack3 = getImageID(); run("Make Montage...", "columns=5 rows=1 scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage2.tif"); close(); selectImage(substack3); close(); selectImage(monty); run("Make Substack...", "slices=1,2,3,4,6"); substack3 = getImageID(); run("Make Montage...", "columns=5 rows=1 scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage3.tif"); close(); selectImage(substack3); close(); selectImage(MAX); close(); selectImage(monty); close(); close(); } > else if (BFimage==true && channels==4) { //print("3 fluorescent channels and one BF image"); run("Duplicate...", "duplicate channels=1-4"); rename(title+"_"+i); newtitle = getTitle; run("8-bit"); run("Z Project...", "projection=[Max Intensity]"); saveAs("tiff", dir+newtitle+"_MAXprj.tif"); run("Image Sequence... ", "format=TIFF start=0 digits=2 save=dir"); MAX = getImageID(); run("Make Substack...", "channels=1-3"); fchanMAX = getImageID(); run("Stack Slicer", "split_channels keep_original stack_order=XYCZT"); selectImage(fchanMAX); run("RGB Color"); saveAs("tiff", dir+newtitle+"_MAXprj_RGB.tif"); selectImage(MAX); run("Make Substack...", "channels=4"); run("Images to Stack", "name=[Stack] title=[] use"); run("Colors...", "foreground=white background=white"); run("Make Montage...", "columns=5 rows=1 scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage.tif"); close(); close(); close(); close(); close(); } > else if (BFimage==true && channels==5) { //print("4 fluorescent channels and one BF image"); run("Duplicate...", "duplicate channels=1-5"); rename(title+"_"+i); newtitle = getTitle; run("8-bit"); Im1 = getImageID(); run("Z Project...", "projection=[Max Intensity]"); MAX = getImageID(); saveAs("tiff", dir+newtitle+"_MAXprj.tif"); run("Image Sequence... ", "format=TIFF start=0 digits=2 save=dir"); selectImage(MAX); run("Make Substack...", "channels=1-4"); substack3 = getImageID(); run("Stack Slicer", "split_channels keep_original stack_order=XYCZT"); selectImage(MAX); run("Make Substack...", "channels=1,3,4"); substack1 = getImageID(); run("RGB Color"); saveAs("tiff", dir+newtitle+"_MAXprj_RGBch1-3-4.tif"); selectImage(substack1); close(); selectImage(MAX); run("Make Substack...", "channels=2,3,4"); substack2 = getImageID(); run("RGB Color"); saveAs("tiff", dir+newtitle+"_MAXprj_RGBch2-3-4.tif"); selectImage(substack2); close(); selectImage(MAX); run("Duplicate...", "duplicate channels=5"); run("Images to Stack", "name=[Stack] title=[] use"); monty = getImageID(); run("Make Montage...", "columns=7 rows=1 scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage1.tif"); close(); selectImage(monty); run("Make Substack...", "slices=1,2,3,4,5,7"); substack3 = getImageID(); run("Make Montage...", "columns=6 rows=1 scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage2.tif"); close(); selectImage(substack3); close(); selectImage(monty); run("Make Substack...", "slices=1,2,3,4,6,7"); substack3 = getImageID(); run("Make Montage...", "columns=6 rows=1 scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage3.tif"); //selectImage(substack3); close(); //selectImage(Im1); close(); //selectImage(MAX); close(); //selectImage(monty); close(); close(); close(); }} > > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi rstj srejt,
The formatting and the fact that your macro expects given types of images makes it difficult to isolate your specific problem. However you could leave your print statements to better follow what your code is doing and use the run("Close All") command instead of multiple close(); statements. A simple close() might hit the Log window and leave one of your images open, spoiling the rest of your workflow. Also, you have a missing semicolon after Dialog.addCheckbox("BF image in stack?", true) . Sincerely, Jerome On 17 July 2013 13:03, rstj srejt <[hidden email]> wrote: > apologies for repeating, but in my mail program the macro text is not > displayed properly. I have repasted this below. I hope it displays > properly this time. > //setBatchMode(true); > Dialog.create("Mikes macro"); Dialog.addCheckbox("BF image in stack?", > true) Dialog.show(); BFimage = Dialog.getCheckbox(); dir = > getDirectory("Choose a Directory"); > ids=newArray(nImages); for (i=0;i<nImages;i++) { selectImage(i+1); > title = getTitle; //print(title); > ids[i]=getImageID; getDimensions(w, h, channels, slices, frames); > if (BFimage==false && channels==3) { //print("3 fluorescent > channels no BF"); run("Duplicate...", "duplicate channels=1-3"); > rename(title+"_"+i); newtitle = getTitle; run("8-bit"); run("Z > Project...", "projection=[Max Intensity]"); saveAs("tiff", > dir+newtitle+"_MAXprj.tif"); run("Image Sequence... ", "format=TIFF > start=0 digits=2 save=dir"); MAX = getImageID(); run("Stack > Slicer", "split_channels keep_original stack_order=XYCZT"); > selectImage(MAX); run("RGB Color"); saveAs("tiff", > dir+newtitle+"_MAXprj_RGB.tif"); run("Images to Stack", > "name=[Stack] title=[] use"); run("Make Montage...", "columns=4 rows=1 > scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage.tif"); > close(); close(); close(); close(); } > else if (BFimage==false && channels==4) { //print("4 fluorescent > channels no BF"); run("Duplicate...", "duplicate channels=1-4"); > rename(title+"_"+i); newtitle = getTitle; run("8-bit"); run("Z > Project...", "projection=[Max Intensity]"); MAX = getImageID(); > saveAs("tiff", dir+newtitle+"_MAXprj.tif"); run("Image Sequence... ", > "format=TIFF start=0 digits=2 save=dir"); run("Stack Slicer", > "split_channels keep_original stack_order=XYCZT"); selectImage(MAX); > run("Make Substack...", "channels=1,3,4"); substack1 = getImageID(); > run("RGB Color"); saveAs("tiff", > dir+newtitle+"_MAXprj_RGBch1-3-4.tif"); selectImage(substack1); close(); > selectImage(MAX); run("Make Substack...", "channels=2,3,4"); > substack2 = getImageID(); run("RGB Color"); saveAs("tiff", > dir+newtitle+"_MAXprj_RGBch2-3-4.tif"); selectImage(substack2); close(); > run("Images to Stack", "name=[Stack] title=[] use"); monty = > getImageID(); run("Make Montage...", "columns=6 rows=1 scale=1 > border=5"); saveAs("tiff", dir+newtitle+"_Montage1.tif"); close(); > selectImage(monty); run("Make Substack...", "slices=1-5"); > substack3 = getImageID(); run("Make Montage...", "columns=5 rows=1 > scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage2.tif"); > close(); selectImage(substack3); close(); selectImage(monty); > run("Make Substack...", "slices=1,2,3,4,6"); substack3 = > getImageID(); run("Make Montage...", "columns=5 rows=1 scale=1 > border=5"); saveAs("tiff", dir+newtitle+"_Montage3.tif"); close(); > selectImage(substack3); close(); selectImage(MAX); > close(); selectImage(monty); close(); close(); } > else if (BFimage==true && channels==4) { //print("3 fluorescent > channels and one BF image"); run("Duplicate...", "duplicate > channels=1-4"); rename(title+"_"+i); newtitle = getTitle; > run("8-bit"); run("Z Project...", "projection=[Max Intensity]"); > saveAs("tiff", dir+newtitle+"_MAXprj.tif"); run("Image Sequence... ", > "format=TIFF start=0 digits=2 save=dir"); MAX = getImageID(); > run("Make Substack...", "channels=1-3"); fchanMAX = getImageID(); > run("Stack Slicer", "split_channels keep_original > stack_order=XYCZT"); selectImage(fchanMAX); run("RGB Color"); > saveAs("tiff", dir+newtitle+"_MAXprj_RGB.tif"); selectImage(MAX); > run("Make Substack...", "channels=4"); run("Images to Stack", > "name=[Stack] title=[] use"); run("Colors...", "foreground=white > background=white"); run("Make Montage...", "columns=5 rows=1 > scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage.tif"); > close(); close(); close(); close(); close(); > } > else if (BFimage==true && channels==5) { //print("4 fluorescent > channels and one BF image"); run("Duplicate...", "duplicate > channels=1-5"); rename(title+"_"+i); newtitle = getTitle; > run("8-bit"); Im1 = getImageID(); run("Z Project...", > "projection=[Max Intensity]"); MAX = getImageID(); saveAs("tiff", > dir+newtitle+"_MAXprj.tif"); run("Image Sequence... ", "format=TIFF > start=0 digits=2 save=dir"); selectImage(MAX); run("Make > Substack...", "channels=1-4"); substack3 = getImageID(); > run("Stack Slicer", "split_channels keep_original stack_order=XYCZT"); > selectImage(MAX); run("Make Substack...", "channels=1,3,4"); > substack1 = getImageID(); run("RGB Color"); saveAs("tiff", > dir+newtitle+"_MAXprj_RGBch1-3-4.tif"); selectImage(substack1); close(); > selectImage(MAX); run("Make Substack...", "channels=2,3,4"); > substack2 = getImageID(); run("RGB Color"); saveAs("tiff", > dir+newtitle+"_MAXprj_RGBch2-3-4.tif"); selectImage(substack2); close(); > selectImage(MAX); run("Duplicate...", "duplicate channels=5"); > run("Images to Stack", "name=[Stack] title=[] use"); monty = > getImageID(); run("Make Montage...", "columns=7 rows=1 scale=1 > border=5"); saveAs("tiff", dir+newtitle+"_Montage1.tif"); close(); > selectImage(monty); run("Make Substack...", "slices=1,2,3,4,5,7"); > substack3 = getImageID(); run("Make Montage...", "columns=6 rows=1 > scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage2.tif"); > close(); selectImage(substack3); close(); selectImage(monty); > run("Make Substack...", "slices=1,2,3,4,6,7"); substack3 = > getImageID(); run("Make Montage...", "columns=6 rows=1 scale=1 > border=5"); saveAs("tiff", dir+newtitle+"_Montage3.tif"); > //selectImage(substack3); close(); //selectImage(Im1); > close(); //selectImage(MAX); close(); > //selectImage(monty); close(); close(); close(); }} > > > Date: Tue, 16 Jul 2013 16:54:36 +0000 > > From: [hidden email] > > Subject: macro batch mode problem > > To: [hidden email] > > > > Hello, > > Im currently writing my first real macro which runs fine in normal mode > but not batch mode. The macro is pasted below. Essentially it first asks > whether there is a brightfield image in the stack or not. Based on the > number of channels in the stack and the response to the aforementioned > question it runs one of four blocks of code. If I open multiple 3 or 4 > channel stacks lacking a brightfield image and i run this macro and uncheck > the tick box at the start and push ok it works fine. However, if i add > setBatchMode(true); at the top of the macro it fails. It makes an attempt > at the first stack but never gets beyond this generally failing with stack > slicer saying it needs a stack. I have a suspicion the problem lies > somewhere in one of the close(); statements closing one of my stacks before > it has been processed when in batch mode. Have I done something wrong??? > Im learning as i write basically. > > I also had to remove all print functions with // otherwise if the log > window was closed and i ran the code it would fail every time. However, if > the log window was open it did not fail. Not sure why this is. > > I did try and write something simple to highlight the problem but i cant > figure it out ! > > Any help would be appreciated. > > Thanks > > Mike > > > > > > setBatchMode(true); > > Dialog.create("Mikes macro"); Dialog.addCheckbox("BF image in > stack?", true) Dialog.show(); BFimage = Dialog.getCheckbox(); dir = > getDirectory("Choose a Directory"); > > ids=newArray(nImages); for (i=0;i<nImages;i++) { selectImage(i+1); > title = getTitle; //print(title); > ids[i]=getImageID; getDimensions(w, h, channels, slices, frames); > > if (BFimage==false && channels==3) { //print("3 fluorescent > channels no BF"); run("Duplicate...", "duplicate channels=1-3"); > rename(title+"_"+i); newtitle = getTitle; run("8-bit"); run("Z > Project...", "projection=[Max Intensity]"); saveAs("tiff", > dir+newtitle+"_MAXprj.tif"); run("Image Sequence... ", "format=TIFF > start=0 digits=2 save=dir"); MAX = getImageID(); run("Stack > Slicer", "split_channels keep_original stack_order=XYCZT"); > selectImage(MAX); run("RGB Color"); saveAs("tiff", > dir+newtitle+"_MAXprj_RGB.tif"); run("Images to Stack", > "name=[Stack] title=[] use"); run("Make Montage...", "columns=4 rows=1 > scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage.tif"); > close(); close(); close(); close(); } > > else if (BFimage==false && channels==4) { //print("4 fluorescent > channels no BF"); run("Duplicate...", "duplicate channels=1-4"); > rename(title+"_"+i); newtitle = getTitle; run("8-bit"); run("Z > Project...", "projection=[Max Intensity]"); MAX = getImageID(); > saveAs("tiff", dir+newtitle+"_MAXprj.tif"); run("Image Sequence... ", > "format=TIFF start=0 digits=2 save=dir"); run("Stack Slicer", > "split_channels keep_original stack_order=XYCZT"); selectImage(MAX); > run("Make Substack...", "channels=1,3,4"); substack1 = getImageID(); > run("RGB Color"); saveAs("tiff", > dir+newtitle+"_MAXprj_RGBch1-3-4.tif"); selectImage(substack1); close(); > selectImage(MAX); run("Make Substack...", "channels=2,3,4"); > substack2 = getImageID(); run("RGB Color"); saveAs("tiff", > dir+newtitle+"_MAXprj_RGBch2-3-4.tif"); selectImage(substack2); close(); > run("Images to Stack", "name=[Stack] title=[] use"); monty = > getImageID(); run("Make Montage...", "columns=6 rows=1 scale=1 > border=5"); saveAs("tiff", dir+newtitle+"_Montage1.tif"); close(); > selectImage(monty); run("Make Substack...", "slices=1-5"); > substack3 = getImageID(); run("Make Montage...", "columns=5 rows=1 > scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage2.tif"); > close(); selectImage(substack3); close(); selectImage(monty); > run("Make Substack...", "slices=1,2,3,4,6"); substack3 = > getImageID(); run("Make Montage...", "columns=5 rows=1 scale=1 > border=5"); saveAs("tiff", dir+newtitle+"_Montage3.tif"); close(); > selectImage(substack3); close(); selectImage(MAX); > close(); selectImage(monty); close(); close(); } > > else if (BFimage==true && channels==4) { //print("3 fluorescent > channels and one BF image"); run("Duplicate...", "duplicate > channels=1-4"); rename(title+"_"+i); newtitle = getTitle; > run("8-bit"); run("Z Project...", "projection=[Max Intensity]"); > saveAs("tiff", dir+newtitle+"_MAXprj.tif"); run("Image Sequence... ", > "format=TIFF start=0 digits=2 save=dir"); MAX = getImageID(); > run("Make Substack...", "channels=1-3"); fchanMAX = getImageID(); > run("Stack Slicer", "split_channels keep_original > stack_order=XYCZT"); selectImage(fchanMAX); run("RGB Color"); > saveAs("tiff", dir+newtitle+"_MAXprj_RGB.tif"); selectImage(MAX); > run("Make Substack...", "channels=4"); run("Images to Stack", > "name=[Stack] title=[] use"); run("Colors...", "foreground=white > background=white"); run("Make Montage...", "columns=5 rows=1 > scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage.tif"); > close(); close(); close(); close(); close(); > } > > else if (BFimage==true && channels==5) { //print("4 fluorescent > channels and one BF image"); run("Duplicate...", "duplicate > channels=1-5"); rename(title+"_"+i); newtitle = getTitle; > run("8-bit"); Im1 = getImageID(); run("Z Project...", > "projection=[Max Intensity]"); MAX = getImageID(); saveAs("tiff", > dir+newtitle+"_MAXprj.tif"); run("Image Sequence... ", "format=TIFF > start=0 digits=2 save=dir"); selectImage(MAX); run("Make > Substack...", "channels=1-4"); substack3 = getImageID(); > run("Stack Slicer", "split_channels keep_original stack_order=XYCZT"); > selectImage(MAX); run("Make Substack...", "channels=1,3,4"); > substack1 = getImageID(); run("RGB Color"); saveAs("tiff", > dir+newtitle+"_MAXprj_RGBch1-3-4.tif"); selectImage(substack1); close(); > selectImage(MAX); run("Make Substack...", "channels=2,3,4"); > substack2 = getImageID(); run("RGB Color"); saveAs("tiff", > dir+newtitle+"_MAXprj_RGBch2-3-4.tif"); selectImage(substack2); close(); > selectImage(MAX); run("Duplicate...", "duplicate channels=5"); > run("Images to Stack", "name=[Stack] title=[] use"); monty = > getImageID(); run("Make Montage...", "columns=7 rows=1 scale=1 > border=5"); saveAs("tiff", dir+newtitle+"_Montage1.tif"); close(); > selectImage(monty); run("Make Substack...", "slices=1,2,3,4,5,7"); > substack3 = getImageID(); run("Make Montage...", "columns=6 rows=1 > scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage2.tif"); > close(); selectImage(substack3); close(); selectImage(monty); > run("Make Substack...", "slices=1,2,3,4,6,7"); substack3 = > getImageID(); run("Make Montage...", "columns=6 rows=1 scale=1 > border=5"); saveAs("tiff", dir+newtitle+"_Montage3.tif"); > //selectImage(substack3); close(); //selectImage(Im1); > close(); //selectImage(MAX); close(); > //selectImage(monty); close(); close(); close(); }} > > > > > > -- > > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Thanks for the suggestions Jerome. I missed that semi colon !! but actually
the macro runs fine with or without it outside of batch mode. Likewise, adding it has no effect on the fact the macro fails in batch mode. I sent wayne a couple of example stacks I have the problems with so maybe he can figure it out. I presume I have just done something wrong rather than there being a bug... but I cant figure it out either way. I think you are right... I should try and simplify the macro! :) Unnecessary steps go to highlight my inexperience ! Thanks Mike -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Jerome Mutterer Sent: 17 July 2013 17:28 To: [hidden email] Subject: Re: macro batch mode problem Hi rstj srejt, The formatting and the fact that your macro expects given types of images makes it difficult to isolate your specific problem. However you could leave your print statements to better follow what your code is doing and use the run("Close All") command instead of multiple close(); statements. A simple close() might hit the Log window and leave one of your images open, spoiling the rest of your workflow. Also, you have a missing semicolon after Dialog.addCheckbox("BF image in stack?", true) . Sincerely, Jerome On 17 July 2013 13:03, rstj srejt <[hidden email]> wrote: > apologies for repeating, but in my mail program the macro text is not > displayed properly. I have repasted this below. I hope it displays > properly this time. > //setBatchMode(true); > Dialog.create("Mikes macro"); Dialog.addCheckbox("BF image in stack?", > true) Dialog.show(); BFimage = Dialog.getCheckbox(); dir = > getDirectory("Choose a Directory"); > ids=newArray(nImages); for (i=0;i<nImages;i++) { selectImage(i+1); > title = getTitle; //print(title); > ids[i]=getImageID; getDimensions(w, h, channels, slices, frames); > if (BFimage==false && channels==3) { //print("3 fluorescent > channels no BF"); run("Duplicate...", "duplicate channels=1-3"); > rename(title+"_"+i); newtitle = getTitle; run("8-bit"); run("Z > Project...", "projection=[Max Intensity]"); saveAs("tiff", > dir+newtitle+"_MAXprj.tif"); run("Image Sequence... ", "format=TIFF > start=0 digits=2 save=dir"); MAX = getImageID(); > Slicer", "split_channels keep_original stack_order=XYCZT"); > selectImage(MAX); run("RGB Color"); saveAs("tiff", > dir+newtitle+"_MAXprj_RGB.tif"); run("Images to Stack", > "name=[Stack] title=[] use"); run("Make Montage...", "columns=4 rows=1 > scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage.tif"); > close(); close(); close(); close(); } > else if (BFimage==false && channels==4) { //print("4 fluorescent > channels no BF"); run("Duplicate...", "duplicate channels=1-4"); > rename(title+"_"+i); newtitle = getTitle; run("8-bit"); run("Z > Project...", "projection=[Max Intensity]"); MAX = getImageID(); > saveAs("tiff", dir+newtitle+"_MAXprj.tif"); run("Image Sequence... ", > "format=TIFF start=0 digits=2 save=dir"); run("Stack Slicer", > "split_channels keep_original stack_order=XYCZT"); selectImage(MAX); > run("Make Substack...", "channels=1,3,4"); substack1 = getImageID(); > run("RGB Color"); saveAs("tiff", > dir+newtitle+"_MAXprj_RGBch1-3-4.tif"); selectImage(substack1); > dir+newtitle+close(); > selectImage(MAX); run("Make Substack...", "channels=2,3,4"); > substack2 = getImageID(); run("RGB Color"); saveAs("tiff", > dir+newtitle+"_MAXprj_RGBch2-3-4.tif"); selectImage(substack2); > dir+newtitle+close(); > run("Images to Stack", "name=[Stack] title=[] use"); monty = > getImageID(); run("Make Montage...", "columns=6 rows=1 scale=1 > border=5"); saveAs("tiff", dir+newtitle+"_Montage1.tif"); close(); > selectImage(monty); run("Make Substack...", "slices=1-5"); > substack3 = getImageID(); run("Make Montage...", "columns=5 rows=1 > scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage2.tif"); > close(); selectImage(substack3); close(); > run("Make Substack...", "slices=1,2,3,4,6"); substack3 = > getImageID(); run("Make Montage...", "columns=5 rows=1 scale=1 > border=5"); saveAs("tiff", dir+newtitle+"_Montage3.tif"); close(); > selectImage(substack3); close(); selectImage(MAX); > close(); selectImage(monty); close(); close(); } > else if (BFimage==true && channels==4) { //print("3 fluorescent > channels and one BF image"); run("Duplicate...", "duplicate > channels=1-4"); rename(title+"_"+i); newtitle = getTitle; > run("8-bit"); run("Z Project...", "projection=[Max Intensity]"); > saveAs("tiff", dir+newtitle+"_MAXprj.tif"); run("Image Sequence... ", > "format=TIFF start=0 digits=2 save=dir"); MAX = getImageID(); > run("Make Substack...", "channels=1-3"); fchanMAX = getImageID(); > run("Stack Slicer", "split_channels keep_original > stack_order=XYCZT"); selectImage(fchanMAX); run("RGB Color"); > saveAs("tiff", dir+newtitle+"_MAXprj_RGB.tif"); > run("Make Substack...", "channels=4"); run("Images to Stack", > "name=[Stack] title=[] use"); run("Colors...", "foreground=white > background=white"); run("Make Montage...", "columns=5 rows=1 > scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage.tif"); > close(); close(); close(); close(); close(); > } > else if (BFimage==true && channels==5) { //print("4 fluorescent > channels and one BF image"); run("Duplicate...", "duplicate > channels=1-5"); rename(title+"_"+i); newtitle = getTitle; > run("8-bit"); Im1 = getImageID(); run("Z Project...", > "projection=[Max Intensity]"); MAX = getImageID(); saveAs("tiff", > dir+newtitle+"_MAXprj.tif"); run("Image Sequence... ", "format=TIFF > start=0 digits=2 save=dir"); selectImage(MAX); run("Make > Substack...", "channels=1-4"); substack3 = getImageID(); > run("Stack Slicer", "split_channels keep_original stack_order=XYCZT"); > selectImage(MAX); run("Make Substack...", "channels=1,3,4"); > substack1 = getImageID(); run("RGB Color"); saveAs("tiff", > dir+newtitle+"_MAXprj_RGBch1-3-4.tif"); selectImage(substack1); > dir+newtitle+close(); > selectImage(MAX); run("Make Substack...", "channels=2,3,4"); > substack2 = getImageID(); run("RGB Color"); saveAs("tiff", > dir+newtitle+"_MAXprj_RGBch2-3-4.tif"); selectImage(substack2); > dir+newtitle+close(); > selectImage(MAX); run("Duplicate...", "duplicate channels=5"); > run("Images to Stack", "name=[Stack] title=[] use"); monty = > getImageID(); run("Make Montage...", "columns=7 rows=1 scale=1 > border=5"); saveAs("tiff", dir+newtitle+"_Montage1.tif"); close(); > selectImage(monty); run("Make Substack...", "slices=1,2,3,4,5,7"); > substack3 = getImageID(); run("Make Montage...", "columns=6 rows=1 > scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage2.tif"); > close(); selectImage(substack3); close(); > run("Make Substack...", "slices=1,2,3,4,6,7"); substack3 = > getImageID(); run("Make Montage...", "columns=6 rows=1 scale=1 > border=5"); saveAs("tiff", dir+newtitle+"_Montage3.tif"); > //selectImage(substack3); close(); //selectImage(Im1); > close(); //selectImage(MAX); close(); > //selectImage(monty); close(); close(); close(); }} > > > Date: Tue, 16 Jul 2013 16:54:36 +0000 > > From: [hidden email] > > Subject: macro batch mode problem > > To: [hidden email] > > > > Hello, > > Im currently writing my first real macro which runs fine in normal > > mode > but not batch mode. The macro is pasted below. Essentially it first > asks whether there is a brightfield image in the stack or not. Based > on the number of channels in the stack and the response to the > aforementioned question it runs one of four blocks of code. If I open > multiple 3 or 4 channel stacks lacking a brightfield image and i run > this macro and uncheck the tick box at the start and push ok it works > fine. However, if i add setBatchMode(true); at the top of the macro > it fails. It makes an attempt at the first stack but never gets > beyond this generally failing with stack slicer saying it needs a > stack. I have a suspicion the problem lies somewhere in one of the > close(); statements closing one of my stacks before it has been processed > Im learning as i write basically. > > I also had to remove all print functions with // otherwise if the > > log > window was closed and i ran the code it would fail every time. > However, if the log window was open it did not fail. Not sure why this is. > > I did try and write something simple to highlight the problem but i > > cant > figure it out ! > > Any help would be appreciated. > > Thanks > > Mike > > > > > > setBatchMode(true); > > Dialog.create("Mikes macro"); Dialog.addCheckbox("BF image in > stack?", true) Dialog.show(); BFimage = Dialog.getCheckbox(); dir = > getDirectory("Choose a Directory"); > > ids=newArray(nImages); for (i=0;i<nImages;i++) { selectImage(i+1); > title = getTitle; //print(title); > ids[i]=getImageID; getDimensions(w, h, channels, slices, frames); > > if (BFimage==false && channels==3) { //print("3 fluorescent > channels no BF"); run("Duplicate...", "duplicate channels=1-3"); > rename(title+"_"+i); newtitle = getTitle; run("8-bit"); run("Z > Project...", "projection=[Max Intensity]"); saveAs("tiff", > dir+newtitle+"_MAXprj.tif"); run("Image Sequence... ", "format=TIFF > start=0 digits=2 save=dir"); MAX = getImageID(); > Slicer", "split_channels keep_original stack_order=XYCZT"); > selectImage(MAX); run("RGB Color"); saveAs("tiff", > dir+newtitle+"_MAXprj_RGB.tif"); run("Images to Stack", > "name=[Stack] title=[] use"); run("Make Montage...", "columns=4 rows=1 > scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage.tif"); > close(); close(); close(); close(); } > > else if (BFimage==false && channels==4) { //print("4 fluorescent > channels no BF"); run("Duplicate...", "duplicate channels=1-4"); > rename(title+"_"+i); newtitle = getTitle; run("8-bit"); run("Z > Project...", "projection=[Max Intensity]"); MAX = getImageID(); > saveAs("tiff", dir+newtitle+"_MAXprj.tif"); run("Image Sequence... ", > "format=TIFF start=0 digits=2 save=dir"); run("Stack Slicer", > "split_channels keep_original stack_order=XYCZT"); selectImage(MAX); > run("Make Substack...", "channels=1,3,4"); substack1 = getImageID(); > run("RGB Color"); saveAs("tiff", > dir+newtitle+"_MAXprj_RGBch1-3-4.tif"); selectImage(substack1); > dir+newtitle+close(); > selectImage(MAX); run("Make Substack...", "channels=2,3,4"); > substack2 = getImageID(); run("RGB Color"); saveAs("tiff", > dir+newtitle+"_MAXprj_RGBch2-3-4.tif"); selectImage(substack2); > dir+newtitle+close(); > run("Images to Stack", "name=[Stack] title=[] use"); monty = > getImageID(); run("Make Montage...", "columns=6 rows=1 scale=1 > border=5"); saveAs("tiff", dir+newtitle+"_Montage1.tif"); close(); > selectImage(monty); run("Make Substack...", "slices=1-5"); > substack3 = getImageID(); run("Make Montage...", "columns=5 rows=1 > scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage2.tif"); > close(); selectImage(substack3); close(); > run("Make Substack...", "slices=1,2,3,4,6"); substack3 = > getImageID(); run("Make Montage...", "columns=5 rows=1 scale=1 > border=5"); saveAs("tiff", dir+newtitle+"_Montage3.tif"); close(); > selectImage(substack3); close(); selectImage(MAX); > close(); selectImage(monty); close(); close(); } > > else if (BFimage==true && channels==4) { //print("3 fluorescent > channels and one BF image"); run("Duplicate...", "duplicate > channels=1-4"); rename(title+"_"+i); newtitle = getTitle; > run("8-bit"); run("Z Project...", "projection=[Max Intensity]"); > saveAs("tiff", dir+newtitle+"_MAXprj.tif"); run("Image Sequence... ", > "format=TIFF start=0 digits=2 save=dir"); MAX = getImageID(); > run("Make Substack...", "channels=1-3"); fchanMAX = getImageID(); > run("Stack Slicer", "split_channels keep_original > stack_order=XYCZT"); selectImage(fchanMAX); run("RGB Color"); > saveAs("tiff", dir+newtitle+"_MAXprj_RGB.tif"); > run("Make Substack...", "channels=4"); run("Images to Stack", > "name=[Stack] title=[] use"); run("Colors...", "foreground=white > background=white"); run("Make Montage...", "columns=5 rows=1 > scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage.tif"); > close(); close(); close(); close(); close(); > } > > else if (BFimage==true && channels==5) { //print("4 fluorescent > channels and one BF image"); run("Duplicate...", "duplicate > channels=1-5"); rename(title+"_"+i); newtitle = getTitle; > run("8-bit"); Im1 = getImageID(); run("Z Project...", > "projection=[Max Intensity]"); MAX = getImageID(); saveAs("tiff", > dir+newtitle+"_MAXprj.tif"); run("Image Sequence... ", "format=TIFF > start=0 digits=2 save=dir"); selectImage(MAX); run("Make > Substack...", "channels=1-4"); substack3 = getImageID(); > run("Stack Slicer", "split_channels keep_original stack_order=XYCZT"); > selectImage(MAX); run("Make Substack...", "channels=1,3,4"); > substack1 = getImageID(); run("RGB Color"); saveAs("tiff", > dir+newtitle+"_MAXprj_RGBch1-3-4.tif"); selectImage(substack1); > dir+newtitle+close(); > selectImage(MAX); run("Make Substack...", "channels=2,3,4"); > substack2 = getImageID(); run("RGB Color"); saveAs("tiff", > dir+newtitle+"_MAXprj_RGBch2-3-4.tif"); selectImage(substack2); > dir+newtitle+close(); > selectImage(MAX); run("Duplicate...", "duplicate channels=5"); > run("Images to Stack", "name=[Stack] title=[] use"); monty = > getImageID(); run("Make Montage...", "columns=7 rows=1 scale=1 > border=5"); saveAs("tiff", dir+newtitle+"_Montage1.tif"); close(); > selectImage(monty); run("Make Substack...", "slices=1,2,3,4,5,7"); > substack3 = getImageID(); run("Make Montage...", "columns=6 rows=1 > scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage2.tif"); > close(); selectImage(substack3); close(); > run("Make Substack...", "slices=1,2,3,4,6,7"); substack3 = > getImageID(); run("Make Montage...", "columns=6 rows=1 scale=1 > border=5"); saveAs("tiff", dir+newtitle+"_Montage3.tif"); > //selectImage(substack3); close(); //selectImage(Im1); > close(); //selectImage(MAX); close(); > //selectImage(monty); close(); close(); close(); }} > > > > > > -- > > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Michael Cundell
On Jul 16, 2013, at 12:54 PM, rstj srejt wrote:
> Hello, > Im currently writing my first real macro which runs fine in normal mode but not batch mode. The macro is pasted below. Essentially it first asks whether there is a brightfield image in the stack or not. Based on the number of channels in the stack and the response to the aforementioned question it runs one of four blocks of code. If I open multiple 3 or 4 channel stacks lacking a brightfield image and i run this macro and uncheck the tick box at the start and push ok it works fine. However, if i add setBatchMode(true); at the top of the macro it fails. It makes an attempt at the first stack but never gets beyond this generally failing with stack slicer saying it needs a stack. I have a suspicion the problem lies somewhere in one of the close(); statements closing one of my stacks before it has been processed when in batch mode. Have I done something wrong??? Im learning as i write basically. Modify the macro so that it opens the stacks to be processed when the macro is in batch mode. Before opening and processing a stack, the macro should call run("Close All") to insure no images are open. The basic structure should be similar to the following macro, which z-projects all the stacks in a folder, saving the projections in another folder. -wayne setBatchMode(true); dir1 = getDirectory("Choose Input Folder"); dir2 = getDirectory("Choose Output Folder"); list = getFileList(dir1); for (i=0; i<list.length; i++) { run("Close All"); open(dir1 + list[i]); run("Z Project...", "projection=[Max Intensity]"); saveAs("tiff", dir2+getTitle()); } run("Close All"); > I also had to remove all print functions with // otherwise if the log window was closed and i ran the code it would fail every time. However, if the log window was open it did not fail. Not sure why this is. > I did try and write something simple to highlight the problem but i cant figure it out ! > Any help would be appreciated. > Thanks > Mike > > > setBatchMode(true); > Dialog.create("Mikes macro"); Dialog.addCheckbox("BF image in stack?", true) Dialog.show(); BFimage = Dialog.getCheckbox(); dir = getDirectory("Choose a Directory"); > ids=newArray(nImages); for (i=0;i<nImages;i++) { selectImage(i+1); title = getTitle; //print(title); ids[i]=getImageID; getDimensions(w, h, channels, slices, frames); > if (BFimage==false && channels==3) { //print("3 fluorescent channels no BF"); run("Duplicate...", "duplicate channels=1-3"); rename(title+"_"+i); newtitle = getTitle; run("8-bit"); run("Z Project...", "projection=[Max Intensity]"); saveAs("tiff", dir+newtitle+"_MAXprj.tif"); run("Image Sequence... ", "format=TIFF start=0 digits=2 save=dir"); MAX = getImageID(); run("Stack Slicer", "split_channels keep_original stack_order=XYCZT"); selectImage(MAX); run("RGB Color"); saveAs("tiff", dir+newtitle+"_MAXprj_RGB.tif"); run("Images to Stack", "name=[Stack] title=[] use"); run("Make Montage...", "columns=4 rows=1 scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage.tif"); close(); close(); close(); close(); } > else if (BFimage==false && channels==4) { //print("4 fluorescent channels no BF"); run("Duplicate...", "duplicate channels=1-4"); rename(title+"_"+i); newtitle = getTitle; run("8-bit"); run("Z Project...", "projection=[Max Intensity]"); MAX = getImageID(); saveAs("tiff", dir+newtitle+"_MAXprj.tif"); run("Image Sequence... ", "format=TIFF start=0 digits=2 save=dir"); run("Stack Slicer", "split_channels keep_original stack_order=XYCZT"); selectImage(MAX); run("Make Substack...", "channels=1,3,4"); substack1 = getImageID(); run("RGB Color"); saveAs("tiff", dir+newtitle+"_MAXprj_RGBch1-3-4.tif"); selectImage(substack1); close(); selectImage(MAX); run("Make Substack...", "channels=2,3,4"); substack2 = getImageID(); run("RGB Color"); saveAs("tiff", dir+newtitle+"_MAXprj_RGBch2-3-4.tif"); selectImage(substack2); close(); run("Images to Stack", "name=[Stack] title=[] use"); monty = getImageID(); run("Make Montage...", "columns=6 rows=1 scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage1.tif"); close(); selectImage(monty); run("Make Substack...", "slices=1-5"); substack3 = getImageID(); run("Make Montage...", "columns=5 rows=1 scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage2.tif"); close(); selectImage(substack3); close(); selectImage(monty); run("Make Substack...", "slices=1,2,3,4,6"); substack3 = getImageID(); run("Make Montage...", "columns=5 rows=1 scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage3.tif"); close(); selectImage(substack3); close(); selectImage(MAX); close(); selectImage(monty); close(); close(); } > else if (BFimage==true && channels==4) { //print("3 fluorescent channels and one BF image"); run("Duplicate...", "duplicate channels=1-4"); rename(title+"_"+i); newtitle = getTitle; run("8-bit"); run("Z Project...", "projection=[Max Intensity]"); saveAs("tiff", dir+newtitle+"_MAXprj.tif"); run("Image Sequence... ", "format=TIFF start=0 digits=2 save=dir"); MAX = getImageID(); run("Make Substack...", "channels=1-3"); fchanMAX = getImageID(); run("Stack Slicer", "split_channels keep_original stack_order=XYCZT"); selectImage(fchanMAX); run("RGB Color"); saveAs("tiff", dir+newtitle+"_MAXprj_RGB.tif"); selectImage(MAX); run("Make Substack...", "channels=4"); run("Images to Stack", "name=[Stack] title=[] use"); run("Colors...", "foreground=white background=white"); run("Make Montage...", "columns=5 rows=1 scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage.tif"); close(); close(); close(); close(); close(); } > else if (BFimage==true && channels==5) { //print("4 fluorescent channels and one BF image"); run("Duplicate...", "duplicate channels=1-5"); rename(title+"_"+i); newtitle = getTitle; run("8-bit"); Im1 = getImageID(); run("Z Project...", "projection=[Max Intensity]"); MAX = getImageID(); saveAs("tiff", dir+newtitle+"_MAXprj.tif"); run("Image Sequence... ", "format=TIFF start=0 digits=2 save=dir"); selectImage(MAX); run("Make Substack...", "channels=1-4"); substack3 = getImageID(); run("Stack Slicer", "split_channels keep_original stack_order=XYCZT"); selectImage(MAX); run("Make Substack...", "channels=1,3,4"); substack1 = getImageID(); run("RGB Color"); saveAs("tiff", dir+newtitle+"_MAXprj_RGBch1-3-4.tif"); selectImage(substack1); close(); selectImage(MAX); run("Make Substack...", "channels=2,3,4"); substack2 = getImageID(); run("RGB Color"); saveAs("tiff", dir+newtitle+"_MAXprj_RGBch2-3-4.tif"); selectImage(substack2); close(); selectImage(MAX); run("Duplicate...", "duplicate channels=5"); run("Images to Stack", "name=[Stack] title=[] use"); monty = getImageID(); run("Make Montage...", "columns=7 rows=1 scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage1.tif"); close(); selectImage(monty); run("Make Substack...", "slices=1,2,3,4,5,7"); substack3 = getImageID(); run("Make Montage...", "columns=6 rows=1 scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage2.tif"); close(); selectImage(substack3); close(); selectImage(monty); run("Make Substack...", "slices=1,2,3,4,6,7"); substack3 = getImageID(); run("Make Montage...", "columns=6 rows=1 scale=1 border=5"); saveAs("tiff", dir+newtitle+"_Montage3.tif"); //selectImage(substack3); close(); //selectImage(Im1); close(); //selectImage(MAX); close(); //selectImage(monty); close(); close(); close(); }} > > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |