Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
IJ-macros
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Zahra Alirezaeizanjani
IJ-macros
Commits
c83994e7
Commit
c83994e7
authored
9 years ago
by
Marius Hintsche
Browse files
Options
Downloads
Patches
Plain Diff
output result as a single stack
with option to save to disk
parent
a4490b33
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
GroupedProjections.ijm
+53
-31
53 additions, 31 deletions
GroupedProjections.ijm
with
53 additions
and
31 deletions
GroupedProjections.ijm
+
53
−
31
View file @
c83994e7
// Creates stack projections for subgroups
// Creates stack projections for subgroups
// and saves them to disk.
// and saves them to disk.
basePath=getDirectory
("Choose
out
put f
older
");
//TODO file=File.openDialog
("Choose
in
put f
ile
");
//
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();
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment