ImageToImageStep#

class petpal.pipelines.preproc_steps.ImageToImageStep(name: str, function: petpal.pipelines.steps_base.Callable, input_image_path: str, output_image_path: str, *args, **kwargs)#

Bases: petpal.pipelines.steps_base.FunctionBasedStep

A step in a processing pipeline for processing and transforming image files. This class handles input and output image paths, executes image transformation functions, and provides methods for setting inputs from other steps and inferring output paths.

Attention

The passed function must have the following arguments order: func(input_image, output_image, *args, **kwargs) where input_image and output_image can be named something else. The first argument must be an input image path, and the second argument must be an output image path.

Variables:
  • input_image_path (str) – Path to the input image file.

  • output_image_path (str) – Path to the output image file.

See also

Initializes an ImageToImageStep with specified parameters.

Parameters:
  • name (str) – The name of the step.

  • function (Callable) – The function to execute.

  • input_image_path (str) – Path to the input image file.

  • output_image_path (str) – Path to the output image file.

  • *args – Additional positional arguments for the transformation function.

  • **kwargs – Additional keyword arguments for the transformation function.

Notes

The passed function must have the following arguments order: func(input_image, output_image, *args, **kwargs) where input_image and output_image can be named something else. The first argument must be an input image path, and the second argument must be an output image path.

execute(copy_meta_file: bool = True) None#

Executes the function and optionally copies meta-data information using safe_copy_meta.

Parameters:

copy_meta_file (bool) – Whether to copy meta information from input to output image. Defaults to True.

Notes

Function must have the following arguments order: (input_image_path, output_image_path, *args, **kwargs) where input_image and output_image are abritrary names.

__str__()#

Provides a string representation of the ImageToImageStep instance.

Returns:

str – A string representation of the instance.

set_input_as_output_from(*sending_steps) None#

Sets the input image path based on the output from a specified sending step.

Parameters:

sending_step (FunctionBasedStep) – The step from which to derive the input image path.

can_potentially_run()#

Checks if the step can potentially run based on input and output paths. Checks if all path related arguments are non-empty strings.

Returns:

bool – True if the step can potentially run, False otherwise.

infer_outputs_from_inputs(out_dir: str, der_type='preproc', suffix: str = 'pet', ext: str = '.nii.gz', **extra_desc)#

Infers the output file path based on the input image path and other parameters.

Parameters:
  • out_dir (str) – Directory where the outputs will be saved.

  • der_type (str) – Type of derivatives. Defaults to ‘preproc’.

  • suffix (str, optional) – Suffix for the output files. Defaults to ‘pet’.

  • ext (str, optional) – Extension for the output files. Defaults to ‘.nii.gz’.

  • **extra_desc – Additional descriptive parameters.

classmethod default_threshold_cropping(name: str = 'thresh_crop', **overrides)#

Creates a default instance for threshold cropping using SimpleAutoImageCropper. All paths are empty-strings.

Parameters:
  • name (str) – Name of the step. Defaults to ‘thresh_crop’.

  • **overrides – Override default parameters.

Returns:

ImageToImageStep – A new instance for threshold cropping.

classmethod default_windowed_moco(name: str = 'windowed_moco', verbose=False, **overrides)#

Creates a default instance for motion correction of frames using a windowed strategy. See windowed_motion_corr_to_target for more details. All paths are empty-strings.

Parameters:
  • name (str) – Name of the step. Defaults to ‘windowed_moco’.

  • verbose

  • **overrides

Returns:

ImageToImageStep – A new instance for windowed motion correction of frames.

classmethod default_register_pet_to_t1(name: str = 'register_pet_to_t1', reference_image_path='', verbose=False, **overrides)#

Creates a default instance for registering PET to T1 image using register_pet. All paths are empty-strings.

Parameters:
  • name (str) – Name of the step. Defaults to ‘register_pet_to_t1’

  • reference_image_path (str) – Path to the reference image.

  • verbose (bool) – Whether to run in verbose mode.

  • **overrides – Override default parameters.

Returns:

ImageToImageStep – A new instance for registering PET to T1 image.

classmethod default_rescale_image(name: str = 'rescale_image', **overrides)#

Creates a default step-instance for rescaling an image using rescale_image.

The defaults for this step will divide the input image by 37000.0 which is usually done to go from kBq/ml to nCi/ml.

Notes

The function rescale_image is wrapped using ANTsImageToANTsImage since steps require input and output paths.

Parameters:
  • name (str) – Name of the step. Defaults to ‘rescale_image’.

  • **overrides

Returns:

ImageToImageStep – A new step instance for rescaling the input image.

classmethod default_warp_pet_to_atlas(name: str = 'warp_pet_to_atlas', anat_image_path: str = '', atlas_image_path: str = '', **overrides)#

Creates a default step instance for warping a PET image to an atlas using warp_pet_to_atlas().

Note

The defaults for this step do not include the anat_image_path or atlas_image_path, as these will depend on the pipeline construction. These paths will need to be set before a pipeline will be able to run.

Parameters:
  • name (str) – Name of the step. Defaults to ‘warp_pet_to_atlas’.

  • anat_image_path (str) – Path to anatomical image used to compute transform to atlas space. Defaults to an empty string ‘’.

  • atlas_image_path (str) – Path to atlas image to which pet will be warped (indirectly, via the anatomical image).

  • **overrides – Override default parameters

Returns:

ImageToImageStep – A new step instance for warping the pet image to atlas space.

get_function_args_not_set_in_kwargs() ArgsDict#

Retrieves arguments of the function that are not set in the keyword arguments.

Returns:

ArgsDict – A dictionary of function arguments that have not been set in the keyword arguments.

get_empty_default_kwargs() list#

Identifies arguments that have not been provided and lack default values.

Returns:

list – A list of argument names that have no default values and are not provided.

validate_kwargs_for_non_default_have_been_set() None#

Validates that all mandatory arguments have been provided.

Raises:

RuntimeError – If any mandatory arguments are missing.

generate_kwargs_from_args() ArgsDict#

Converts positional arguments into keyword arguments.

Returns:

ArgsDict – A dictionary where positional arguments are mapped to their corresponding parameter names.

__repr__()#

Returns an unambiguous string representation of the FunctionBasedStep instance.

Returns:

str – A string representation showing how the FunctionBasedStep can be recreated.

all_args_non_empty_strings()#

Checks if all positional arguments are non-empty strings.

Returns:

bool – True if all positional arguments are non-empty strings, False otherwise.

all_kwargs_non_empty_strings()#

Checks if all keyword arguments are non-empty strings.

Returns:

bool – True if all keyword arguments are non-empty strings, False otherwise.

__call__(*args, **kwargs)#