dosma.core.numpy_routines.concatenate

dosma.core.numpy_routines.concatenate(xs, axis: int = - 1)[source]

Concatenate medical images.

Image concatenation is slightly different if the axis is a spatial axis (one of the first 3 dimensions) or a non-spatial dimension.

If concatenating along a non-spatial dimension, the image dimensions for all other axes and affine matrix of each x must be the same, which is standard for concatenation.

If concatenating along a spatial dimension, all images must have the same direction and pixel spacing. Additionally, the scanner origin for all spatial axes not being concatenated should be the same. The origin for other scans should be consecutive. For example, if images are concatenated on axis=i, a spatial axis, then xs[0].scanner_origin + xs[0]..

Images will be auto-oriented to the orientation of the first medical volume.

Parameters
  • xs (Sequence[MedicalVolume]) – The medical images to concatenate.

  • axis (int, optional) – The axis to concatenate on.

Returns

The concatenated medical image.

Return type

MedicalVolume

Note

Headers are not set unless all inputs have headers of the same shape. This functionality may change in the future.

Examples

>>> mv = dm.MedicalVolume([[[[0],[1],[2],[3]]]], affine=np.eye(4))
>>> np.concatenate([mv, mv], axis=-1)  # Concatenate along non-spatial dimension
MedicalVolume(volume=[[[[0 0], [1 1], [2 2], [3 3]]]])
>>> mv2 = dm.MedicalVolume(
    [[[[4],[5],[6],[7]]]],
    affine=[[1,0,0,0], [0,1,0,0],[0,0,1,4],[0,0,0,1]]
)
>>> np.concatenate([mv, mv2], axis=2)  # Concatenate along spatial dimension
MedicalVolume(volume=[[[[0]
    [1]
    [2]
    [3]
    [0]
    [1]
    [2]
    [3]]]])