Basic ImgLib2 question: make a mean projection

Hi all,

I´m trying to get my head around ImgLib2 plugins. Starting simply and trying to make a mean projection of Z stack.

I am trying to follow a script exemplifying just process but keeping getting the following error.

The method project(IterableInterval<V>, RandomAccessibleInterval<T>, UnaryComputerOp<Iterable<T>,V>, int) in the type TransformNamespace is not applicable for the arguments (Img<T>, ImgPlus<capture#7-of ? extends RealType<?>>, Op, int)

the code that I have is this:

@Parameter
private Dataset currentData;

@Parameter
private OpService opService;
 
/*
\* class code
*/

int d;
int[ ] projected_dimensions = new int[currentData.numDimensions()-1];
int dim = currentData.dimensionIndex(Axes.Z);
for (d=0; d < currentData.numDimensions();++d){
    if(d != dim)
         projected_dimensions[d]= (int) currentData.dimension(d); 
}
		
Img<T> proj = (Img<T>) ij.op().create().img(projected_dimensions);

Op mean_op = ij.op().op(Ops.Stats.Mean.NAME, currentData.getImgPlus());
opService.transform().project(proj, currentData.getImgPlus(), mean_op, dim); //This is where the error occurs 

Any pointers to tutorials regarding this error and working with image projection and image calculation would be very helpful.

Cheers,

1 Like

Here is your example with one small difference.

The project function needs a UnaryComputerOp, so I had to cast the mean_op to UnaryComputerOp, or alternatively I had to use computers.Unary to get the op.

It works for me now. Let me know if this solves your problem.

Brian

2 Likes

Thanks that did the trick!!
I was way off mark because I though the problem was with the way I was creating the output image!!!

Just one question: In your example when you create a new Img for the output of the Op service. Is there a reason for this, or can one use directly the output proj image create before hand?

Img<T> proj = (Img<T>) ij.op().create().img(projected_dimensions);
Img<T> projection=(Img<T>)ij.op().transform().project(proj, currentData.getImgPlus(), mean_op, dim);

Thanks again,
Helio