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 // Creates stack projections for subgroups
// and saves them to disk. // and saves them to disk.
basePath=getDirectory("Choose output folder"); //TODO file=File.openDialog("Choose input file");
//file=File.openDialog("Choose input file"); //TODO Import file as virtual Stack (using BioFormats as neccesary)
// Import file as virtual Stack (using BioFormats as neccesary) inputID = getImageID();
myStack = getImageID(); if (nSlices==1) {exit("This macro only operates on stacks.")};
//Ask user for settings //Ask user for settings
Dialog.create("Projection Method"); Dialog.create("Projection Method");
Dialog.addChoice("Method:", newArray("Max Intensity", "Min Intensity","Median","Average Intensity")); Dialog.addChoice("Method:", newArray("Max Intensity", "Min Intensity","Median","Average Intensity"));
Dialog.addNumber("Size of substack",300); Dialog.addNumber("Size of substack",300);
Dialog.addCheckbox("Save result to disk", false)
Dialog.show(); Dialog.show();
method=Dialog.getChoice(); method=Dialog.getChoice();
subStackSize = Dialog.getNumber(); subStackSize = Dialog.getNumber();
saveToDisk = Dialog.getCheckbox();
//Check if sub stack will fit in memory //Check if sub stack will fit in memory
maxMem = parseInt(IJ.maxMemory()); maxMem = parseInt(IJ.maxMemory());
...@@ -25,45 +27,65 @@ if (stackMem > maxMem) { ...@@ -25,45 +27,65 @@ if (stackMem > maxMem) {
tStart = getTime(); tStart = getTime();
setBatchMode(true); setBatchMode(true);
methodPrefix = replace(method,' ','-'); methodPrefix = replace(method,' ','-');
resultName = methodPrefix;
//TODO save inputName and store in image info
iMax = floor(nSlices()/subStackSize)+1; iMax = floor(nSlices()/subStackSize)+1;
print("Saving result files to "+basePath+" ..."); for (i=0; i<iMax; i++) {
for (i=0; i<(iMax-1); i++) { selectImage(inputID);
//TODO handle smaller substack at the end of original stack if (i<(iMax-1)) {
start=i*subStackSize+1; start=i*subStackSize+1;
stop=start+subStackSize; stop=start+subStackSize-1;
calculateProjection(start,stop,i,method); }
print(methodPrefix+"_"+IJ.pad(start,5)+"-"+IJ.pad(stop,5)+".tif"); else {
function saveSlice(basePath,methodPrefix,start,stop); start=i*subStackSize+1;
selectWindow("SubStack"+i); stop=nSlices();
close(); }
selectImage(myStack); sliceName = methodPrefix+"_"+IJ.pad(start,5)+"-"+IJ.pad(stop,5);
} calculateProjection(start,stop,i,method);
//Handle last substack separately rename(sliceName);
start=(iMax-1)*subStackSize+1; if (i>1) {
stop=nSlices(); addSlice(resultName,resultName,getTitle());
calculateProjection(start,stop,i,method); selectImage(resultName);
print(methodPrefix+"_"+IJ.pad(start,5)+"-"+IJ.pad(stop,5)+".tif"); setSlice(nSlices);
function saveSlice(basePath,methodPrefix,start,stop); setMetadata("Label", sliceName);
selectWindow("SubStack"+i); }
close(); else if (i==1) {
selectImage(myStack); 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(); tStop = getTime();
walltime = (tStop-tStart)/1000/60; 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); setBatchMode(false);
//TODO open completed Max Proj Stack
print("Done! (took "+d2s(walltime,1)+" min to complete."); print("Done! (took "+d2s(walltime,1)+" min to complete.");
function calculateProjection(iStart,iStop,nSlice,method) { function calculateProjection(iStart,iStop,nSlice,method) {
run("Duplicate...", "title=SubStack"+nSlice+" duplicate range="+iStart+"-"+iStop); 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) { function addSlice(resultTitle,in1,in2) {
//TODO save result as tiff stack run("Concatenate...", " title=["+resultTitle+"] image1="+in1+" image2="+in2);
run("Save", "save=["+path+prefix+"_"+IJ.pad(start,5)+"-"+IJ.pad(iStop,5)+".tif]");
showStatus("Grouped Stack Proj. ("+i+"/"+iMax+"):"); showStatus("Grouped Stack Proj. ("+i+"/"+iMax+"):");
showProgress(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