These are chat archives for fiji/fiji

Nov 2016
Hadrien Mary
Nov 09 2016 17:56 UTC
Hey guys, someone know an easy way to do z stack on a dataset in Python with IJ2 ? Using ops maybe ?
Hadrien Mary
Nov 09 2016 18:04 UTC
I found this ops.transform().project(imp, ops.stats().max, 1) but IJ2 want the first argument to be out. Do I need to create an empty ImgPlus ? Can't I just get the out as the return object of the ops (the Python way) ?
Hadrien Mary
Nov 09 2016 18:16 UTC

Got it with that

z_dim = data.dimensionIndex(Axes.Z)
projected_dimensions = [data.dimension(d) for d in range(0, data.numDimensions()) if d != z_dim]
z_projected = ops.create().img(projected_dimensions)
max_op = ops.op(Ops.Stats.Max, data)
ops.transform().project(z_projected, data, max_op, z_dim)
ij.ui().show("z_proj", z_projected)

If you know a quicker way to do it that would be cool (5 lines for a z projection seems pretty long...)

Curtis Rueden
Nov 09 2016 19:36 UTC
@hadim in general using ops.create().something is the way to precreate the needed output image. Yes, we want the framework to do that automatically whenever possible, and have taken care to make many ops work this way. But not all of them do yet.
(This is called "hybrid CF" or computer/function op, BTW.)
It is absolutely vital to have the computer version that works on preallocated output buffers though, so that buffers can be reused.
I'm glad you managed to get it working, at the end.
If you like, file an issue at asking for a transform.project function, rather than only a computer.
This would shorten your code above considerably.
Hadrien Mary
Nov 09 2016 19:44 UTC
Thanks for the explanation.