Skip to content
Snippets Groups Projects
Commit c83994e7 authored by Marius Hintsche's avatar Marius Hintsche
Browse files

output result as a single stack

with option to save to disk
parent a4490b33
No related branches found
No related tags found
No related merge requests found
// Creates stack projections for subgroups
// and saves them to disk.
basePath=getDirectory("Choose output folder");
//file=File.openDialog("Choose input file");
// Import file as virtual Stack (using BioFormats as neccesary)
myStack = getImageID();
//TODO file=File.openDialog("Choose input file");
//TODO Import file as virtual Stack (using BioFormats as neccesary)
inputID = getImageID();
if (nSlices==1) {exit("This macro only operates on stacks.")};
//Ask user for settings
Dialog.create("Projection Method");
Dialog.addChoice("Method:", newArray("Max Intensity", "Min Intensity","Median","Average Intensity"));
Dialog.addNumber("Size of substack",300);
Dialog.addCheckbox("Save result to disk", false)
Dialog.show();
method=Dialog.getChoice();
subStackSize = Dialog.getNumber();
saveToDisk = Dialog.getCheckbox();
//Check if sub stack will fit in memory
maxMem = parseInt(IJ.maxMemory());
......@@ -25,45 +27,65 @@ if (stackMem > maxMem) {
tStart = getTime();
setBatchMode(true);
methodPrefix = replace(method,' ','-');
resultName = methodPrefix;
//TODO save inputName and store in image info
iMax = floor(nSlices()/subStackSize)+1;
print("Saving result files to "+basePath+" ...");
for (i=0; i<(iMax-1); i++) {
//TODO handle smaller substack at the end of original stack
start=i*subStackSize+1;
stop=start+subStackSize;
calculateProjection(start,stop,i,method);
print(methodPrefix+"_"+IJ.pad(start,5)+"-"+IJ.pad(stop,5)+".tif");
function saveSlice(basePath,methodPrefix,start,stop);
selectWindow("SubStack"+i);
close();
selectImage(myStack);
}
//Handle last substack separately
start=(iMax-1)*subStackSize+1;
stop=nSlices();
calculateProjection(start,stop,i,method);
print(methodPrefix+"_"+IJ.pad(start,5)+"-"+IJ.pad(stop,5)+".tif");
function saveSlice(basePath,methodPrefix,start,stop);
selectWindow("SubStack"+i);
close();
selectImage(myStack);
for (i=0; i<iMax; i++) {
selectImage(inputID);
if (i<(iMax-1)) {
start=i*subStackSize+1;
stop=start+subStackSize-1;
}
else {
start=i*subStackSize+1;
stop=nSlices();
}
sliceName = methodPrefix+"_"+IJ.pad(start,5)+"-"+IJ.pad(stop,5);
calculateProjection(start,stop,i,method);
rename(sliceName);
if (i>1) {
addSlice(resultName,resultName,getTitle());
selectImage(resultName);
setSlice(nSlices);
setMetadata("Label", sliceName);
}
else if (i==1) {
addSlice(resultName,slice1,sliceName);
selectImage(resultName);
setSlice(1);
setMetadata("Label", slice1);
setSlice(2);
setMetadata("Label", sliceName);
setBatchMode("show");
}
else if (i==0) {
slice1=getTitle();
}
selectImage(inputID);
}
tStop = getTime();
walltime = (tStop-tStart)/1000/60;
selectImage(resultName);
run("Enhance Contrast...", "saturated=0.4 process_all");
if (saveToDisk) {
//TODO ask user for file name istead of folder only
basePath=getDirectory("Choose output folder");
saveAs("Tiff",basePath+resultName+"_grouped");
}
setBatchMode(false);
//TODO open completed Max Proj Stack
print("Done! (took "+d2s(walltime,1)+" min to complete.");
function calculateProjection(iStart,iStop,nSlice,method) {
run("Duplicate...", "title=SubStack"+nSlice+" duplicate range="+iStart+"-"+iStop);
run("Z Project...", "start=1 stop="+(iStop-iStart+1)+" projection=["+method+"]");
if (nSlices>1) {
run("Z Project...", "start=1 stop="+(iStop-iStart+1)+" projection=["+method+"]");
}
}
function saveSlice(path,prefix,iStart,iStop) {
//TODO save result as tiff stack
run("Save", "save=["+path+prefix+"_"+IJ.pad(start,5)+"-"+IJ.pad(iStop,5)+".tif]");
function addSlice(resultTitle,in1,in2) {
run("Concatenate...", " title=["+resultTitle+"] image1="+in1+" image2="+in2);
showStatus("Grouped Stack Proj. ("+i+"/"+iMax+"):");
showProgress(i/iMax);
close();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment