learning.as_real

Contents

learning.as_real#

bartorch.learning.as_real()#

Stack the real and imaginary parts of input along a new leading axis.

The channel-first counterpart of torch.view_as_real(), as convolutional networks and torchio.ScalarImage take channels.

Parameters:

input (torch.Tensor) – Complex, of any shape. A real tensor is given a zero imaginary part.

Returns:

Real, of shape (2, *input.shape).

Return type:

torch.Tensor

Notes

torchio.ScalarImage takes four axes, (channels, x, y, z), so a two-dimensional image is given a trailing axis of length one first.

Examples

>>> volume = learning.as_real(image)                      # (2, x, y, z)
>>> subject = torchio.Subject(image=torchio.ScalarImage(tensor=volume))