Macro to open more than one stack-series with two channels in the same folder
Posted by Sergi.novo on
URL: http://imagej.273.s1.nabble.com/Macro-to-open-more-than-one-stack-series-with-two-channels-in-the-same-folder-tp5001189.html
Hello,
I have this macro to open a stack-serie with two channels:
// Macro for Reading Z-Stacks from Leica SP5
// Volker Hilsenstein - last change 14.8.2012
// Ask for source folder and get list of files in that folder
folder = getDirectory("F://");
filelist = getFileList(folder);
print(folder);
print(lengthOf(filelist));
enhance_contrast = true;
subsample = 1; // subsample the stack on loading, 1 means no subsampling, 2 is every other slice
// check for presence of channels
// and example filename
iC0 = 0;
iC1 = 0;
sum = 0;
filename_example = "";
for(i=0; i<lengthOf(filelist) ; i++) {
if(indexOf(filelist[i],"C00")>-1) {
if(iC0==0) {
print("Channel 0 present.");
}
iC0++;
if(lengthOf(filename_example)==0) {
filename_example=filelist[i];
}
}
else if(!iC1 && indexOf(filelist[i],"C01")>-1) {
if(iC1==0) {
print("Channel 1 present.");
}
iC1++;
if(lengthOf(filename_example)==0) {
filename_example=filelist[i];
}
}
}
sum=iC0+iC1;
if(sum==0) {
exit("no channels found");
}
print("First file of stack sequence is " + filename_example + " in folder " + folder);
if(iC0>0) {
run("Image Sequence...", "open="+ folder + "//" + filename_example+ " number=sum starting=1 increment=" + subsample + " scale=100 file=C00 or=[] sort");
rename("tmpC00");
if(enhance_contrast) {
run("Set Scale...", "distance=0 known=0 pixel=1 unit=pixel");
makeRectangle(26, 467, 468, 37);
run("BG Subtraction from ROI", "number=2");
run("Select None");
run("Enhance Contrast...", "saturated=0.4 normalize process_all");
}
sC0="tmpC00";
}
else {
sC0="*None*";
}
if(iC1>0) {
run("Image Sequence...", "open="+ folder + "//" + filename_example+ " number=sum starting=1 increment=" + subsample + " scale=100 file=C01 or=[] sort");
rename("tmpC01");
if(enhance_contrast) {
run("Set Scale...", "distance=0 known=0 pixel=1 unit=pixel");
makeRectangle(26, 467, 468, 37);
run("BG Subtraction from ROI", "number=2");
run("Select None");
run("Enhance Contrast...", "saturated=0.4 normalize process_all");
}
sC1="tmpC01";
}
else {
sC1="*None*";
}
I would like to adapt this macro to open more than one stack-series stored in the same folder. Here, an example of a folder with three different series:
image--L0000--S00--U00--V00--J08--E02--O00--X01--Y02--T0000--Z00--C00--001.ome.tif
image--L0000--S00--U00--V00--J08--E02--O00--X01--Y02--T0000--Z00--C00--002.ome.tif
image--L0000--S00--U00--V00--J08--E02--O00--X01--Y02--T0000--Z00--C00.ome.tif
image--L0000--S00--U00--V00--J08--E02--O00--X01--Y02--T0000--Z01--C00--001.ome.tif
image--L0000--S00--U00--V00--J08--E02--O00--X01--Y02--T0000--Z01--C00--002.ome.tif
image--L0000--S00--U00--V00--J08--E02--O00--X01--Y02--T0000--Z01--C00.ome.tif
image--L0000--S00--U00--V00--J08--E02--O00--X01--Y02--T0000--Zn--C00--001.ome.tif
image--L0000--S00--U00--V00--J08--E02--O00--X01--Y02--T0000--Zn--C00--002.ome.tif
image--L0000--S00--U00--V00--J08--E02--O00--X01--Y02--T0000--Zn--C00.ome.tif
Many thanks!