Hi there,
I have several stacks taken at different time points which I want to combine in to a 4D stack automatically. I have the following macro which works well however the stacks are in the wrong order when this is run on a folder on a server but not a folder on a computer hard drive. I think it's to do with the individual stacks being opened in the wrong order. The stacks are named alphabetically so that week 1 is named 'a', week two 'b' etc. Any help greatly appreciated! Thanks, Jo //PART 1 Choose input, starts dir=getDirectory("Choose folder with registered stacks"); listFiles(dir); function listFiles(dir) { list = getFileList(dir); for (i=0; i<list.length; i++) { if (endsWith(list[i], "/")) listFiles(""+dir+list[i]); else //this now should be recursive for subdirectories setBatchMode(true); FolderList = getFileList(dir); } processFolder(dir); function processFolder(dir) { list = getFileList(dir); for (i=0; i<list.length; i++) { if(endsWith(list[i], ".tif")); open(dir+list[i]); title1 = getTitle; title1b=split(title1, "_"); len1=lengthOf(title1); title1a=substring(title1, len1-12, len1-4); //add label to each slice of each stack corresponding to its session Stack.getDimensions(width, height, channels, slices, frames); for (m=0; m<frames+1; m++){ Stack.setFrame(m); for (j=1; j<slices+1; j++) { Stack.setSlice(j); titleL = getTitle; titleLa=substring(titleL, 13,14); run("Set Label...", "label=&titleLa"); } } if(title1a!="register") { close(); } else { title1 = getTitle; run("Z Project...", "projection=[Max Intensity]"); run("Measure"); err=getResult("Mean", 0); selectWindow("MAX_" +title1); //print(err); if(err==0){ print(title1+ " No signal detected"); run("Close"); selectWindow("MAX_" +title1); run("Close"); if (isOpen("Results")) { selectWindow("Results"); run("Clear Results"); } } else { if (isOpen("Results")) { selectWindow("Results"); run("Close"); selectWindow("MAX_" +title1); run("Close"); } } pth=File.getParent(dir); geg=getDirectory("image"); } } } pth=File.getParent(dir); geg=getDirectory("image") ; geg2= File.separator + geg; title1 = getTitle; len1=lengthOf(title1); title2= substring(title1, 0,13); title3= substring(title1, 16, len1-4); title4=title2+title3; run("Concatenate...", "all_open title=[] open"); saveAs("tiff", geg2+File.separator +title4+ "_4D"); close(); } |
Free forum by Nabble | Edit this page |