Motion Simulation Parts#

atommic.collections.motioncorrection.parts.motionsimulation.get_center_rect(image: torch.tensor, center_percentage: float = 0.02, dim: int = 0) torch.tensor[source]#

Get a center rectangle of a given dimension.

Parameters
  • image (torch.tensor) – The image to get the center rectangle from.

  • center_percentage (float) – The percentage of the image to take as the center rectangle.

  • dim (int) – The dimension to take the center rectangle from.

Returns

The center rectangle.

Return type

torch.tensor

atommic.collections.motioncorrection.parts.motionsimulation.segment_array_by_locs(shape: Sequence[int], locations: Sequence[int]) torch.tensor[source]#

Generate a segmentation mask based on a list of locations.

Parameters
  • shape (Sequence[int]) – The shape of the array to segment.

  • locations (Sequence[int]) – The locations to segment the array into.

Returns

The segmentation mask.

Return type

torch.tensor

atommic.collections.motioncorrection.parts.motionsimulation.segments_to_random_indices(shape: Sequence[int], seg_lengths: Sequence[int]) torch.tensor[source]#

Generate a segmentation mask based on a list of locations.

Parameters
  • shape (Sequence[int]) – The shape of the array to segment.

  • seg_lengths (Sequence[int]) – The lengths of the segments to generate.

Returns

The segmentation mask.

Return type

torch.tensor

atommic.collections.motioncorrection.parts.motionsimulation.segments_to_random_blocks(shape: Sequence[int], seg_lengths: Sequence[int]) torch.tensor[source]#

Generate a segmentation mask based on a list of locations.

Parameters
  • shape (Sequence[int]) – The shape of the array to segment.

  • seg_lengths (Sequence[int]) – The lengths of the segments to generate.

Returns

The segmentation mask.

Return type

torch.tensor

atommic.collections.motioncorrection.parts.motionsimulation.create_rand_partition(im_length: int, num_segments: int)[source]#

Create a random partition of an array.

Parameters
  • im_length (int) – The length of the array to partition.

  • num_segments (int) – The number of segments to partition the array into.

Returns

The partition locations.

Return type

list

atommic.collections.motioncorrection.parts.motionsimulation.create_rotation_matrix_3d(angles: Sequence[float]) torch.tensor[source]#

Create a 3D rotation matrix.

Parameters

angles (Sequence[float]) – The angles to rotate the matrix by.

Returns

The rotation matrix.

Return type

torch.tensor

atommic.collections.motioncorrection.parts.motionsimulation.translate_kspace(freq_domain: torch.tensor, translations: torch.tensor) torch.tensor[source]#

Translate a k-space array.

Parameters
  • freq_domain (torch.tensor) – The k-space array to translate.

  • translations (torch.tensor) – The translations to apply to the k-space array.

Returns

The translated k-space array.

Return type

torch.tensor

class atommic.collections.motioncorrection.parts.motionsimulation.MotionSimulation(motion_type: str = 'piecewise_transient', angle: float = 0, translation: float = 10, center_percentage: float = 0.02, motion_percentage: Sequence[float] = (15, 20), num_segments: int = 8, random_num_segments: bool = False, non_uniform: bool = False, spatial_dims: Sequence[int] = (-2, -1))[source]#

Bases: object

Simulates random translations and rotations in the frequency domain.

Examples

>>> from atommic.collections.motioncorrection.parts import MotionSimulation
>>> import torch
>>> motion_simulation = MotionSimulation()
>>> kspace = torch.randn(1, 1, 256, 256, 2)
>>> motion_kspace = motion_simulation(kspace)
>>> motion_kspace.shape
torch.Size([1, 1, 256, 256, 2])
__init__(motion_type: str = 'piecewise_transient', angle: float = 0, translation: float = 10, center_percentage: float = 0.02, motion_percentage: Sequence[float] = (15, 20), num_segments: int = 8, random_num_segments: bool = False, non_uniform: bool = False, spatial_dims: Sequence[int] = (-2, -1))[source]#

Inits MotionSimulation.

Parameters
  • motion_type (str) – The motion_type of motion to simulate.

  • angle (float) – The angle to rotate the k-space array by.

  • translation (float) – The translation to apply to the k-space array.

  • center_percentage (float) – The percentage of the k-space array to center the motion.

  • motion_percentage (Sequence[float]) – The percentage of the k-space array to apply the motion.

  • num_segments (int) – The number of segments to partition the k-space array into.

  • random_num_segments (bool) – Whether to randomly generate the number of segments.

  • non_uniform (bool) – Whether to use non-uniform sampling.

  • spatial_dims (Sequence[int]) – The spatial dimensions to apply the motion to.

forward(kspace, translations_rotations: Optional[Tuple[torch.Tensor, torch.Tensor]] = None, apply_backward_transform: bool = False, apply_forward_transform: bool = False) torch.Tensor[source]#

Forward pass of MotionSimulation.

Parameters
  • kspace (torch.Tensor) – The kspace to apply the motion to.

  • translations_rotations (Optional[Tuple[torch.Tensor, torch.Tensor]]) – The translations and rotations to apply to the kspace. If None, a random trajectory is generated.

  • apply_backward_transform (bool) – Placeholder for the backward transform. Generalizes the Composer, but not used.

  • apply_forward_transform (bool) – Placeholder for the forward transform. Generalizes the Composer, but not used.

Returns

The kspace with the motion applied.

Return type

torch.Tensor