MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / _get_affine

Method _get_affine

monai/data/image_reader.py:1562–1579  ·  view source on GitHub ↗

Get the affine matrix of the image, it can be used to correct spacing, orientation or execute spatial transforms. Args: img: A `NrrdImage` loaded from image file

(self, header: dict)

Source from the content-addressed store, hash-verified

1560 return _stack_images(img_array, compatible_meta), compatible_meta
1561
1562 def _get_affine(self, header: dict) -> np.ndarray:
1563 """
1564 Get the affine matrix of the image, it can be used to correct
1565 spacing, orientation or execute spatial transforms.
1566
1567 Args:
1568 img: A `NrrdImage` loaded from image file
1569
1570 """
1571 direction = header["space directions"]
1572 origin = header["space origin"]
1573
1574 x, y = direction.shape
1575 affine_diam = min(x, y) + 1
1576 affine: np.ndarray = np.eye(affine_diam)
1577 affine[:x, :y] = direction.T
1578 affine[: (affine_diam - 1), -1] = origin # len origin is always affine_diam - 1
1579 return affine
1580
1581 def _switch_lps_ras(self, header: dict) -> dict:
1582 """

Callers 1

get_dataMethod · 0.95

Calls 1

minFunction · 0.85

Tested by

no test coverage detected