ImageToImageStep =============================================== .. py: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: :py:obj:`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. :ivar input_image_path: Path to the input image file. :vartype input_image_path: str :ivar output_image_path: Path to the output image file. :vartype output_image_path: str .. seealso:: - :meth:`default_threshold_cropping` - :meth:`default_moco_frames_above_mean` - :meth:`default_register_pet_to_t1` Initializes an ImageToImageStep with specified parameters. :param name: The name of the step. :type name: str :param function: The function to execute. :type function: Callable :param input_image_path: Path to the input image file. :type input_image_path: str :param output_image_path: Path to the output image file. :type output_image_path: str :param \*args: Additional positional arguments for the transformation function. :param \*\*kwargs: Additional keyword arguments for the transformation function. .. rubric:: 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. .. py:method:: execute(copy_meta_file: bool = True) -> None Executes the function and optionally copies meta-data information using :func:`safe_copy_meta`. :param copy_meta_file: Whether to copy meta information from input to output image. Defaults to True. :type copy_meta_file: bool .. rubric:: 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. .. py:method:: __str__() Provides a string representation of the ImageToImageStep instance. :returns: *str* -- A string representation of the instance. .. py:method:: set_input_as_output_from(*sending_steps) -> None Sets the input image path based on the output from a specified sending step. :param sending_step: The step from which to derive the input image path. :type sending_step: FunctionBasedStep .. py:method:: 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. .. py:method:: 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. :param out_dir: Directory where the outputs will be saved. :type out_dir: str :param der_type: Type of derivatives. Defaults to 'preproc'. :type der_type: str :param suffix: Suffix for the output files. Defaults to 'pet'. :type suffix: str, optional :param ext: Extension for the output files. Defaults to '.nii.gz'. :type ext: str, optional :param \*\*extra_desc: Additional descriptive parameters. .. py:method:: default_threshold_cropping(name: str = 'thresh_crop', **overrides) :classmethod: Creates a default instance for threshold cropping using :class:`SimpleAutoImageCropper`. All paths are empty-strings. :param name: Name of the step. Defaults to 'thresh_crop'. :type name: str :param \*\*overrides: Override default parameters. :returns: *ImageToImageStep* -- A new instance for threshold cropping. .. py:method:: default_windowed_moco(name: str = 'windowed_moco', verbose=False, **overrides) :classmethod: Creates a default instance for motion correction of frames using a windowed strategy. See :func:`windowed_motion_corr_to_target` for more details. All paths are empty-strings. :param name: Name of the step. Defaults to 'windowed_moco'. :type name: str :param verbose: :param \*\*overrides: :returns: *ImageToImageStep* -- A new instance for windowed motion correction of frames. .. py:method:: default_register_pet_to_t1(name: str = 'register_pet_to_t1', reference_image_path='', verbose=False, **overrides) :classmethod: Creates a default instance for registering PET to T1 image using :func:`register_pet`. All paths are empty-strings. :param name: Name of the step. Defaults to 'register_pet_to_t1' :type name: str :param reference_image_path: Path to the reference image. :type reference_image_path: str :param verbose: Whether to run in verbose mode. :type verbose: bool :param \*\*overrides: Override default parameters. :returns: *ImageToImageStep* -- A new instance for registering PET to T1 image. .. py:method:: default_rescale_image(name: str = 'rescale_image', **overrides) :classmethod: Creates a default step-instance for rescaling an image using :class:`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. .. rubric:: Notes The function :class:`rescale_image` is wrapped using :func:`ANTsImageToANTsImage` since steps require input and output paths. :param name: Name of the step. Defaults to 'rescale_image'. :type name: str :param \*\*overrides: :returns: *ImageToImageStep* -- A new step instance for rescaling the input image. .. py:method:: default_warp_pet_to_atlas(name: str = 'warp_pet_to_atlas', anat_image_path: str = '', atlas_image_path: str = '', **overrides) :classmethod: Creates a default step instance for warping a PET image to an atlas using :func:`~petpal.preproc.register.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. :param name: Name of the step. Defaults to 'warp_pet_to_atlas'. :type name: str :param anat_image_path: Path to anatomical image used to compute transform to atlas space. Defaults to an empty string ''. :type anat_image_path: str :param atlas_image_path: Path to atlas image to which pet will be warped (indirectly, via the anatomical image). :type atlas_image_path: str :param \*\*overrides: Override default parameters :returns: *ImageToImageStep* -- A new step instance for warping the pet image to atlas space. .. py:method:: 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. .. py:method:: 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. .. py:method:: 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. .. py:method:: 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. .. py:method:: __repr__() Returns an unambiguous string representation of the FunctionBasedStep instance. :returns: *str* -- A string representation showing how the FunctionBasedStep can be recreated. .. py:method:: 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. .. py:method:: 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. .. py:method:: __call__(*args, **kwargs)