Weighted average over temporal dimension

Hello all. I have a bunch of 3D scans of the same subject over time joined in a 4D scan using (by JoinSeries) and I have a vector with the phase weights. To create a 3D approximation of this 4D object you might want to multiply with the (normalized) phase weights and then take the sum over that axis.

Is there a one-liner for this in (Simple)ITK or should I resort to turning the vector into an image with the same dimensions, multiply and sum over the axis? The ProjectionImageFilter’s do not seem to support weights.

As an followup question, I’d like to know if there is somehow a way to assign these non-uniform “temporal spacings” in ITK? Currently I use SetMetaData where I set the phase as an additional key, but having non-uniform spacings would be convenient. I see that basically the xarray implementation between ITK <-> xarray basically sets a position per slice. Is there such ITK support?

Your could try something like:

sitk.NaryAdd([img4d[:,:,:,i]*weights[i] for i in range(img4d.GetSize()[3])] ) 

If you use a for loop with the inplace *= it may be a little more efficeint.

Hello @jonasteuwen,

With respect to non-uniform temporal spacings, that isn’t supported in the form of a 4D ITK image. In ITK the steps along an axis are always assumed to have uniform spacing. This works in most 3D+time settings such as standard video.

To have non uniform spacing along the temporal axis you’d have to treat the volumetric video as a list/array of 3D images so that you can associate a variable timestamp with each step.

1 Like

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)

The Cast image filter does not support 4D images. It looks like the error message could use improvement.

1 Like

Thanks. While I can how to resolve that for the above problem, there are more general places where this might be relevant. I’ll open another post!