dosma.core.numpy_routines.clip

dosma.core.numpy_routines.clip(x, x_min, x_max, **kwargs)[source]

Clip the values in the array.

Same as applying numpy.clip() on x.volume. Only one of x_min or x_max can be None.

Parameters:
  • x (MedicalVolume) – Medical image to clip.

  • x_min (array-like or MedicalVolume) – Minimum value. If None, clipping is not performed on this edge.

  • x_max (array-like or MedicalVolume) – Maximum value. If None, clipping is not performed on this edge.

  • kwargs – Optional keyword arguments, see numpy.clip().

Returns:

The clipped medical image.

Return type:

MedicalVolume

Note

The out positional argument is not currently supported.

Examples

>>> mv = MedicalVolume([[[0,1,2,3,4,5,6,7,8,9]]], affine=np.eye(4))
>>> np.clip(mv, 1, 5)  # Clip values between [1, 5]
MedicalVolume(volume=[[[1 1 2 3 4 5 5 5 5 5]]])
>>> np.clip(mv, x_max=5)  # Clip values between (-inf, 5]
MedicalVolume(volume=[[[0 1 2 3 4 5 5 5 5 5]]])