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

add ability to specify overlap of substacks

also specify save target before loop execution
parent c83994e7
No related branches found
No related tags found
No related merge requests found
...@@ -10,12 +10,19 @@ if (nSlices==1) {exit("This macro only operates on stacks.")}; ...@@ -10,12 +10,19 @@ if (nSlices==1) {exit("This macro only operates on stacks.")};
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.addNumber("Overlap (frames)",0);
Dialog.addCheckbox("Save result to disk", false) Dialog.addCheckbox("Save result to disk", false)
Dialog.show(); Dialog.show();
method=Dialog.getChoice(); method=Dialog.getChoice();
subStackSize = Dialog.getNumber(); subStackSize = Dialog.getNumber();
overlap = Dialog.getNumber();
saveToDisk = Dialog.getCheckbox(); saveToDisk = Dialog.getCheckbox();
if (overlap >= subStackSize) {error("Overlap must be smaller than size of substack");}
if (saveToDisk) {
//TODO get fully qualified filename in stead of only directory
basePath=getDirectory("Choose output folder");
}
//Check if sub stack will fit in memory //Check if sub stack will fit in memory
maxMem = parseInt(IJ.maxMemory()); maxMem = parseInt(IJ.maxMemory());
...@@ -29,19 +36,18 @@ setBatchMode(true); ...@@ -29,19 +36,18 @@ setBatchMode(true);
methodPrefix = replace(method,' ','-'); methodPrefix = replace(method,' ','-');
resultName = methodPrefix; resultName = methodPrefix;
//TODO save inputName and store in image info //TODO save inputName and store in image info
//FIXME calculate iMax correctly for overlaps
iMax = floor(nSlices()/subStackSize)+1; iMax = floor(nSlices()/subStackSize)+1;
print(method+" projection on "+iMax+" substacks, each with "+overlap+" slices overlap...");
for (i=0; i<iMax; i++) { for (i=0; i<iMax; i++) {
selectImage(inputID); start=i*subStackSize+1;
if (i<(iMax-1)) { stop=start+subStackSize+overlap;
start=i*subStackSize+1; if (stop > nSlices()) {
stop=start+subStackSize-1;
}
else {
start=i*subStackSize+1;
stop=nSlices(); stop=nSlices();
i = iMax+1;
} }
sliceName = methodPrefix+"_"+IJ.pad(start,5)+"-"+IJ.pad(stop,5); sliceName = methodPrefix+"_"+IJ.pad(start,5)+"-"+IJ.pad(stop,5);
calculateProjection(start,stop,i,method); calculateProjection(start,stop,"SubStack",method);
rename(sliceName); rename(sliceName);
if (i>1) { if (i>1) {
addSlice(resultName,resultName,getTitle()); addSlice(resultName,resultName,getTitle());
...@@ -62,23 +68,24 @@ for (i=0; i<iMax; i++) { ...@@ -62,23 +68,24 @@ for (i=0; i<iMax; i++) {
slice1=getTitle(); slice1=getTitle();
} }
selectImage("SubStack");
close();
selectImage(inputID); selectImage(inputID);
} }
tStop = getTime();
walltime = (tStop-tStart)/1000/60;
selectImage(resultName); selectImage(resultName);
setSlice(1);
run("Enhance Contrast...", "saturated=0.4 process_all"); run("Enhance Contrast...", "saturated=0.4 process_all");
if (saveToDisk) { if (saveToDisk) {
//TODO ask user for file name istead of folder only
basePath=getDirectory("Choose output folder");
saveAs("Tiff",basePath+resultName+"_grouped"); saveAs("Tiff",basePath+resultName+"_grouped");
} }
setBatchMode(false); setBatchMode(false);
tStop = getTime();
walltime = (tStop-tStart)/1000/60;
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,resultTitle,method) {
run("Duplicate...", "title=SubStack"+nSlice+" duplicate range="+iStart+"-"+iStop); run("Duplicate...", "title="+resultTitle+" duplicate range="+iStart+"-"+iStop);
if (nSlices>1) { if (nSlices>1) {
run("Z Project...", "start=1 stop="+(iStop-iStart+1)+" projection=["+method+"]"); run("Z Project...", "start=1 stop="+(iStop-iStart+1)+" projection=["+method+"]");
} }
......
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