tomosipo.from_perspective

tomosipo.from_perspective(*, pos=None, w=None, v=None, u=None, vol=None, ignore_scale=True)[source]

Create a perspective transform

This perspective transform converts the given frame of reference to the “world” coordinate frame with origin (0, 0, 0) and coordinate axes Z, Y, X.

The frame of reference can either be explicitly provided using the pos, w, v, u parameters. Alternatively, the frame of reference can be specified using a volume geometry.

To perform the perspective transformation without scaling any of the coordinate axes (thus only performing rotation and translation), provide ignore_scale=True.

Parameters:
  • pos (Tuple[float, float, float] | Iterable[Tuple[float, float, float]] | ndarray | Tuple[float, float, float, float] | Iterable[Tuple[float, float, float, float]]) – The position of the new frame of reference.

  • w (Tuple[float, float, float] | Iterable[Tuple[float, float, float]] | ndarray | Tuple[float, float, float, float] | Iterable[Tuple[float, float, float, float]]) – The first coordinate of the new frame of reference.

  • v (Tuple[float, float, float] | Iterable[Tuple[float, float, float]] | ndarray | Tuple[float, float, float, float] | Iterable[Tuple[float, float, float, float]]) – The second coordinate of the new frame of reference.

  • u (Tuple[float, float, float] | Iterable[Tuple[float, float, float]] | ndarray | Tuple[float, float, float, float] | Iterable[Tuple[float, float, float, float]]) – The third coordinate of the new frame of reference.

  • vol (Any) – A volume (vector) geometry that specifies the frame of reference. If provided, the pos, w, v, and u parameters are taken from the volume.

  • ignore_scale (bool) – If True, do not perform any scaling of the coordinate axes. Effectively, the transform only performs rotation and translation in most cases.

Returns:

A transform describing the shift in perspective.

Return type:

Transform

Examples

Create a translation from (1, 2, 3) to (0, 0, 0):

>>> ts.from_perspective(pos=(1, 2, 3), w=(1, 0, 0), v=(0, 1, 0), u=(0, 0, 1))
Transform(
    [[[ 1.  0.  0. -1.]
  [ 0.  1.  0. -2.]
  [ 0.  0.  1. -3.]
  [ 0.  0.  0.  1.]]]
)

Create equivalent translation, using the vol parameter:

>>> ts.from_perspective(vol=ts.volume(pos=(1, 2, 3)))
Transform(
    [[[ 1.  0.  0. -1.]
  [ 0.  1.  0. -2.]
  [ 0.  0.  1. -3.]
  [ 0.  0.  0.  1.]]]
)

Ignore scaling of the coordinate axes:

>>> ts.from_perspective(pos=(1, 2, 3), w=(2, 0, 0), v=(0, 2, 0), u=(0, 0, 2), ignore_scale=True)
Transform(
    [[[ 1.  0.  0. -1.]
  [ 0.  1.  0. -2.]
  [ 0.  0.  1. -3.]
  [ 0.  0.  0.  1.]]]
)

Scale the coordinate axes as well:

>>> ts.from_perspective(pos=(1, 2, 3), w=(2, 0, 0), v=(0, 2, 0), u=(0, 0, 2), ignore_scale=False)
Transform(
    [[[ 0.5  0.   0.  -0.5]
  [ 0.   0.5  0.  -1. ]
  [ 0.   0.   0.5 -1.5]
  [ 0.   0.   0.   1. ]]]
)