tomosipo.to_perspective

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

Create a perspective transform

This perspective transform converts the “world” coordinate frame to another frame of reference.

The other frame of reference can either be explicitly provided using the pos, w, v, u parameters. Alternatively, the other 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 (0, 0, 0) to (1, 2, 3):

>>> ts.to_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.to_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.to_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.to_perspective(pos=(1, 2, 3), w=(2, 0, 0), v=(0, 2, 0), u=(0, 0, 2), ignore_scale=False)
Transform(
    [[[2. 0. 0. 1.]
  [0. 2. 0. 2.]
  [0. 0. 2. 3.]
  [0. 0. 0. 1.]]]
)