Skip to content

Instantly share code, notes, and snippets.

@tferr
Last active November 14, 2016 18:14
Show Gist options
  • Save tferr/4018e924f8a63e38ff90ec67041a1536 to your computer and use it in GitHub Desktop.
Save tferr/4018e924f8a63e38ff90ec67041a1536 to your computer and use it in GitHub Desktop.
# @ImageJ ij
# @Dataset data
# @String(label="Projection Type",choices={"Max","Mean","Median","Min", "StdDev", "Sum"}) proj_type
from net.imagej.axis import Axes
from net.imagej.ops import Ops
def proj_method(method):
return {
'Max': Ops.Stats.Max,
'Mean': Ops.Stats.Mean,
'Median': Ops.Stats.Median,
'Min': Ops.Stats.Min,
'StdDev': Ops.Stats.StdDev,
'Sum': Ops.Stats.Sum,
}.get(method, Ops.Stats.Max)
def main():
# Select which dimension to project
z_dim = data.dimensionIndex(Axes.Z)
if z_dim == -1:
print("Z dimension not found.")
return
if data.dimension(z_dim) < 2:
print("Z dimension has only one frame.")
return
# Write the output dimensions
projected_dimensions = [data.dimension(d) for d in range(0, data.numDimensions()) if d != z_dim]
# Create the output image
z_projected = ij.op().create().img(projected_dimensions)
# Create the op and run it
proj_op = ij.op().op(proj_method(proj_type), data)
ij.op().transform().project(z_projected, data, proj_op, z_dim)
# Create a dataset
z_projected = ij.dataset().create(z_projected)
# Set the correct axes (is that needed ?)
axes = [data.axis(d) for d in range(0, data.numDimensions()) if d != z_dim]
z_projected.setAxes(axes)
print(z_projected)
ij.ui().show("z_projected", z_projected)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment