Pencil beam CT Module

pencilbeam: Simulation of 2D Pencil Beam CT Data Using Various Acquisition Strategies

This module provides a set of functions to simulate 2D pencil beam computed tomography (CT) scanning using different acquisition strategies. The scanning methods include stepped, continuous, and zigzag/zigzig scanning patterns, with either rotation or translation as the fast axis. These simulations are useful for studying scanning efficiencies, sinogram generation, and reconstruction approaches in pencil beam CT.

Available Acquisition Strategies:

  1. Stepped Scans: - zigzig_stepped_translation: Zigzig scan with translation as the primary movement axis, moving in discrete steps. - zigzig_stepped_rotation: Zigzig scan with rotation as the primary movement axis, moving in discrete steps. - zigzag_stepped_translation: Zigzag scan with translation as the primary movement axis, moving in discrete steps. - zigzag_stepped_rotation: Zigzag scan with rotation as the primary movement axis, moving in discrete steps.

  2. Fast-Axis Scans (Continuous Motion): - zigzig_fast_translation: Zigzig scan with translation as the primary movement axis, moving in continuous motion. - zigzig_fast_rotation: Zigzig scan with rotation as the primary movement axis, moving in continuous motion. - zigzag_fast_translation: Zigzag scan with translation as the primary movement axis, moving in continuous motion. - zigzag_fast_rotation: Zigzag scan with rotation as the primary movement axis, moving in continuous motion.

  3. Continuous Scanning: - continuous_rot_trans: Simulates a scan where rotation and translation occur

    simultaneously. The sample rotates continuously over a full 360° while translating.

Each of these functions generates an animated visualization of the scanning process, demonstrating the movement of the sample, the sinogram formation, and the beam behavior (turning on/off in stepped scans). These simulations can be useful for testing scanning strategies, optimizing acquisition times, and developing reconstruction methods for pencil beam CT applications.

@author: Dr A. Vamvakeros

nDTomo.sim.pencilbeam.continuous_rot_trans(image, angles, num_trans_steps, interval=50, cmap='jet')[source]

Simulate a simultaneous continuous rotation and translation scan with the beam always ON.

Parameters:
  • image (np.ndarray) – The original 2D image to be rotated and translated.

  • angles (np.ndarray) – A list of angles (in degrees) defining the rotation path.

  • num_trans_steps (int) – Number of translation steps for one full rotation cycle.

  • interval (int, optional) – Time between frames in milliseconds (default is 50ms).

  • cmap (str, optional) – Colormap for displaying images (default is ‘jet’).

Returns:

  • ani (matplotlib.animation.FuncAnimation) – The created animation.

  • ani_html (str) – HTML representation of the animation for display in Jupyter.

nDTomo.sim.pencilbeam.continuous_rot_trans_optimised(image, angles, num_trans_steps, interval=50, cmap='jet')[source]

Simulate a simultaneous continuous rotation and translation scan with cubic interpolation.

Parameters:
  • image (np.ndarray) – The original 2D image to be rotated and translated.

  • angles (np.ndarray) – A list of angles (in degrees) defining the rotation path.

  • num_trans_steps (int) – Number of translation steps for one full rotation cycle.

  • interval (int, optional) – Time between frames in milliseconds (default is 50ms).

  • cmap (str, optional) – Colormap for displaying images (default is ‘jet’).

Returns:

  • ani (matplotlib.animation.FuncAnimation) – The created animation.

  • ani_html (str) – HTML representation of the animation for display in Jupyter.

nDTomo.sim.pencilbeam.generate_interlaced_angles(nproj, subsets)[source]

Generate interlaced scan angles for a given number of projections and subsets.

Parameters:
  • nproj (int) – Total number of projections (must be a power of 2).

  • subsets (int) – Number of subsets (must be a factor of nproj).

Returns:

  • list of np.ndarray – A list where each element is an array containing the angles for one subset.

  • # Example usage

  • nproj = 120

  • subsets = 8

  • interlaced_angles = generate_interlaced_angles(nproj, subsets)

  • # Print subset angles

  • for i, subset in enumerate(interlaced_angles) – print(f”Subset {i+1}: {subset}”)

nDTomo.sim.pencilbeam.translate_image(image, shift_x, shift_y, subpixel=True, method='interp')[source]

Translate a 2D image by (shift_x, shift_y) pixels using interpolation.

Parameters:
  • image (np.ndarray) – The input 2D image.

  • shift_x (float) – Shift in the x-direction.

  • shift_y (float) – Shift in the y-direction.

  • subpixel (bool, optional) – If True, allows subpixel translations using interpolation.

  • method (str, optional) –

    • “interp”: Uses scipy.ndimage.shift (cubic interpolation).

Returns:

translated_image – The translated image.

Return type:

np.ndarray

nDTomo.sim.pencilbeam.zigzag_fast_rotation(image, angles, interval=50, cmap='jet')[source]

Zigzag scan with rotation as the primary movement axis, moving in continuous motion.

Parameters:
  • image (np.ndarray) – The original 2D image to be rotated and translated.

  • angles (np.ndarray) – A list of angles (in degrees) defining the rotation path.

  • interval (int, optional) – Time between frames in milliseconds (default is 50ms).

  • cmap (str, optional) – Colormap for displaying images (default is ‘jet’).

Returns:

  • ani (matplotlib.animation.FuncAnimation) – The created animation.

  • ani_html (str) – HTML representation of the animation for display in Jupyter.

nDTomo.sim.pencilbeam.zigzag_fast_translation(image, angles, interval=500, cmap='jet')[source]

Zigzag scan with translation as the primary movement axis, moving in continuous motion.

Parameters:
  • image (np.ndarray) – The original 2D image to be rotated.

  • angles (list or np.ndarray) – 1D array of angles (in degrees) for rotation at each frame.

  • interval (int, optional) – Time between frames in milliseconds (default is 500ms).

  • cmap (str, optional) – Colormap for displaying images (default is ‘jet’).

Returns:

  • ani (matplotlib.animation.FuncAnimation) – The created animation.

  • ani_html (str) – HTML representation of the animation for display in Jupyter.

nDTomo.sim.pencilbeam.zigzag_stepped_rotation(image, angles, interval=50, cmap='jet')[source]

Zigzag scan with rotation as the primary movement axis, moving in discrete steps.

Parameters:
  • image (np.ndarray) – The original 2D image to be rotated and translated.

  • angles (np.ndarray) – A list of angles (in degrees) defining the rotation path.

  • interval (int, optional) – Time between frames in milliseconds (default is 50ms).

  • cmap (str, optional) – Colormap for displaying images (default is ‘jet’).

Returns:

  • ani (matplotlib.animation.FuncAnimation) – The created animation.

  • ani_html (str) – HTML representation of the animation for display in Jupyter.

nDTomo.sim.pencilbeam.zigzag_stepped_translation(image, angles, interval=500, cmap='jet')[source]

Zigzag scan with translation as the primary movement axis, moving in discrete steps.

Parameters:
  • image (np.ndarray) – The original 2D image to be rotated.

  • angles (list or np.ndarray) – 1D array of angles (in degrees) for rotation at each frame.

  • interval (int, optional) – Time between frames in milliseconds (default is 500ms).

  • cmap (str, optional) – Colormap for displaying images (default is ‘jet’).

Returns:

  • ani (matplotlib.animation.FuncAnimation) – The created animation.

  • ani_html (str) – HTML representation of the animation for display in Jupyter.

nDTomo.sim.pencilbeam.zigzig_fast_rotation(image, angles, interval=500, cmap='jet')[source]

Zigzig scan with rotation as the primary movement axis, moving in continuous motion.

Parameters:
  • image (np.ndarray) – The original 2D image to be rotated and translated.

  • angles (np.ndarray) – A list of angles (in degrees) defining the rotation path.

  • interval (int, optional) – Time between frames in milliseconds (default is 500ms).

  • cmap (str, optional) – Colormap for displaying images (default is ‘jet’).

Returns:

  • ani (matplotlib.animation.FuncAnimation) – The created animation.

  • ani_html (str) – HTML representation of the animation for display in Jupyter.

nDTomo.sim.pencilbeam.zigzig_fast_translation(image, angles, interval=500, cmap='jet')[source]

Zigzig scan with translation as the primary movement axis, moving in continuous motion.

Parameters:
  • image (np.ndarray) – The original 2D image to be rotated.

  • angles (list or np.ndarray) – 1D array of angles (in degrees) for rotation at each frame.

  • interval (int, optional) – Time between frames in milliseconds (default is 500ms).

  • cmap (str, optional) – Colormap for displaying images (default is ‘jet’).

Returns:

  • ani (matplotlib.animation.FuncAnimation) – The created animation.

  • ani_html (str) – HTML representation of the animation for display in Jupyter.

nDTomo.sim.pencilbeam.zigzig_stepped_rotation(image, angles, interval=50, cmap='jet')[source]

Zigzig scan with rotation as the primary movement axis, moving in discrete steps.

Parameters:
  • image (np.ndarray) – The original 2D image to be rotated and translated.

  • angles (np.ndarray) – A list of angles (in degrees) defining the rotation path.

  • interval (int, optional) – Time between frames in milliseconds (default is 50ms).

  • cmap (str, optional) – Colormap for displaying images (default is ‘jet’).

Returns:

  • ani (matplotlib.animation.FuncAnimation) – The created animation.

  • ani_html (str) – HTML representation of the animation for display in Jupyter.

nDTomo.sim.pencilbeam.zigzig_stepped_translation(image, angles, interval=500, cmap='jet')[source]

Zigzig scan with translation as the primary movement axis, moving in discrete steps.

Parameters:
  • image (np.ndarray) – The original 2D image to be rotated.

  • angles (list or np.ndarray) – 1D array of angles (in degrees) for rotation at each frame.

  • interval (int, optional) – Time between frames in milliseconds (default is 500ms).

  • cmap (str, optional) – Colormap for displaying images (default is ‘jet’).

Returns:

  • ani (matplotlib.animation.FuncAnimation) – The created animation.

  • ani_html (str) – HTML representation of the animation for display in Jupyter.

nDTomo.sim.pencilbeam.zigzig_stepped_translation_optimised(image, angles, interval=500, cmap='jet')[source]

Zigzig scan with translation as the primary movement axis, moving in discrete steps.

Parameters:
  • image (np.ndarray) – The original 2D image to be rotated.

  • angles (list or np.ndarray) – 1D array of angles (in degrees) for rotation at each frame.

  • interval (int, optional) – Time between frames in milliseconds (default is 500ms).

  • cmap (str, optional) – Colormap for displaying images (default is ‘jet’).

Returns:

  • ani (matplotlib.animation.FuncAnimation) – The created animation.

  • ani_html (str) – HTML representation of the animation for display in Jupyter.