lama/elastix/deformations.py
def make_deformations_at_different_scales(config: Union[LamaConfig, dict]) -> Union[None, np.array]:
    """
    Generate jacobian determinants and optionaly defromation vectors

    Parameters
    ----------
    config:
        LamaConfig object if running from other lama module
        Path to config file if running this module independently

    Notes
    -----
    How to generate the hacobian determinants is defined by the config['generate_deformation_fields'] entry.

    toml representation from the LAMA config:

    [generate_deformation_fields]
    192_to_10 = [ "deformable_192_to_10",]

    This will create a set of jacobian determinants and optional deformation fields called 192_to_10 and using the
    the named regisrtation stages in the list.

    Multiple sets of key/value pairs are allowed so that diffrent jacobians determinatnts might be made. For eaxmple
    you may want to include the affine transformation in the jacobians, which would look like so:

    affine_192_to_10 = [ "affine", "deformable_192_to_10"]

    Returns
    -------
    jacobian array if there are any negative values
    """

    if isinstance(config, (str, Path)):
        config = LamaConfig(Path(config))

    if not config['generate_deformation_fields']:
        return

    deformation_dir = config.mkdir('deformations')
    jacobians_dir = config.mkdir('jacobians')
    log_jacobians_dir = config.mkdir('log_jacobians')

    write_vectors = config['write_deformation_vectors']
    write_raw_jacobians = config ['write_raw_jacobians']
    write_log_jacobians = config['write_log_jacobians']

    for deformation_id, stage_info in config['generate_deformation_fields'].items():
        reg_stage_dirs: List[Path] = []

        resolutions: List[int] = []  # Specify the resolutions from a stage to generate defs and jacs from

        if len(stage_info) > 1:

            try:
                int(stage_info[1])
            except ValueError:
                # 1. We are spcifiying multiple lama-specified stages: Use the TransformParameters.O.txt from each stage
                for stage_id in stage_info:
                    reg_stage_dirs.append(config['root_reg_dir'] / stage_id)

            else:
                # 2. It is one stage but we are using the elastix defined stages, which will be specified by ints
                #   Use TransformParameters.O.R<x>.txt files where x is the numbers specified
                reg_stage_dirs.append(config['root_reg_dir'] / stage_info[0])
                resolutions = stage_info[1:]
        else:
            # Just one stage is defined so use the TransformParameters.O.txt from that stage
            reg_stage_dirs.append(config['root_reg_dir'] / stage_info[0])

        deformation_id = str(deformation_id)

        deformation_scale_dir = deformation_dir / deformation_id
        deformation_scale_dir.mkdir()
        jacobians_scale_dir =  jacobians_dir / deformation_id
        jacobians_scale_dir.mkdir()
        log_jacobians_scale_dir = log_jacobians_dir / deformation_id
        log_jacobians_scale_dir.mkdir()

        neg_jac_arr = _generate_deformation_fields(reg_stage_dirs, resolutions, deformation_scale_dir, jacobians_scale_dir,
                                                   log_jacobians_scale_dir, write_vectors, write_raw_jacobians, write_log_jacobians,
                                                   threads=config['threads'], filetype=config['filetype'])
        return neg_jac_arr

    Generate jacobian determinants and optionaly defromation vectors

    Parameters
    ----------
    config:
        LamaConfig object if running from other lama module
        Path to config file if running this module independently

    Notes
    -----
    How to generate the hacobian determinants is defined by the config['generate_deformation_fields'] entry.

    toml representation from the LAMA config:

    [generate_deformation_fields]
    192_to_10 = [ "deformable_192_to_10",]

    This will create a set of jacobian determinants and optional deformation fields called 192_to_10 and using the
    the named regisrtation stages in the list.

    Multiple sets of key/value pairs are allowed so that diffrent jacobians determinatnts might be made. For eaxmple
    you may want to include the affine transformation in the jacobians, which would look like so:

    affine_192_to_10 = [ "affine", "deformable_192_to_10"]

    Returns
    -------
    jacobian array if there are any negative values
    
Generate jacobian determinants and optionaly defromation vectors
Parameters

LamaConfig object if running from other lama module
Path to config file if running this module independently

Notes



toml representation from the LAMA config.



This will create a set of jacobian determinants and optional deformation fields called 192_to_10 and using the
the named regisrtation stages in the list.

Multiple sets of key/value pairs are allowed so that diffrent jacobians determinatnts might be made. For eaxmple
you may want to include the affine transformation in the jacobians, which would look like so.



Returns

jacobian array if there are any negative values
Generate jacobian determinants and optionaly defromation vectors Parameters LamaConfig object if running from other lama module Path to config file if running this module independently Notes toml representation from the LAMA config . This will create a set of jacobian determinants and optional deformation fields called 192_to_10 and using the the named regisrtation stages in the list . Multiple sets of key / value pairs are allowed so that diffrent jacobians determinatnts might be made . For eaxmple you may want to include the affine transformation in the jacobians which would look like so . Returns jacobian array if there are any negative values
def make_deformations_at_different_scales(config: Union[LamaConfig, dict]) -> Union[None, np.array]:
    if isinstance(config, (str, Path)):
        config = LamaConfig(Path(config))
    if not config['generate_deformation_fields']:
        return
    deformation_dir = config.mkdir('deformations')
    jacobians_dir = config.mkdir('jacobians')
    log_jacobians_dir = config.mkdir('log_jacobians')
    write_vectors = config['write_deformation_vectors']
    write_raw_jacobians = config ['write_raw_jacobians']
    write_log_jacobians = config['write_log_jacobians']
    for deformation_id, stage_info in config['generate_deformation_fields'].items():
        reg_stage_dirs: List[Path] = []
        resolutions: List[int] = []  
        if len(stage_info) > 1:
            try:
                int(stage_info[1])
            except ValueError:
                for stage_id in stage_info:
                    reg_stage_dirs.append(config['root_reg_dir'] / stage_id)
            else:
                reg_stage_dirs.append(config['root_reg_dir'] / stage_info[0])
                resolutions = stage_info[1:]
        else:
            reg_stage_dirs.append(config['root_reg_dir'] / stage_info[0])
        deformation_id = str(deformation_id)
        deformation_scale_dir = deformation_dir / deformation_id
        deformation_scale_dir.mkdir()
        jacobians_scale_dir =  jacobians_dir / deformation_id
        jacobians_scale_dir.mkdir()
        log_jacobians_scale_dir = log_jacobians_dir / deformation_id
        log_jacobians_scale_dir.mkdir()
        neg_jac_arr = _generate_deformation_fields(reg_stage_dirs, resolutions, deformation_scale_dir, jacobians_scale_dir,
                                                   log_jacobians_scale_dir, write_vectors, write_raw_jacobians, write_log_jacobians,
                                                   threads=config['threads'], filetype=config['filetype'])
        return neg_jac_arr
def make_deformations_at_different_scales ( config : Union [ LamaConfig , dict ] ) -> Union [ None , np . array ] : if isinstance ( config , ( str , Path ) ) : config = LamaConfig ( Path ( config ) ) if not config [ 'generate_deformation_fields' ] : return deformation_dir = config . mkdir ( 'deformations' ) jacobians_dir = config . mkdir ( 'jacobians' ) log_jacobians_dir = config . mkdir ( 'log_jacobians' ) write_vectors = config [ 'write_deformation_vectors' ] write_raw_jacobians = config [ 'write_raw_jacobians' ] write_log_jacobians = config [ 'write_log_jacobians' ] for deformation_id , stage_info in config [ 'generate_deformation_fields' ] . items ( ) : reg_stage_dirs : List [ Path ] = [ ] resolutions : List [ int ] = [ ] if len ( stage_info ) > 1 : try : int ( stage_info [ 1 ] ) except ValueError : for stage_id in stage_info : reg_stage_dirs . append ( config [ 'root_reg_dir' ] / stage_id ) else : reg_stage_dirs . append ( config [ 'root_reg_dir' ] / stage_info [ 0 ] ) resolutions = stage_info [ 1 : ] else : reg_stage_dirs . append ( config [ 'root_reg_dir' ] / stage_info [ 0 ] ) deformation_id = str ( deformation_id ) deformation_scale_dir = deformation_dir / deformation_id deformation_scale_dir . mkdir ( ) jacobians_scale_dir = jacobians_dir / deformation_id jacobians_scale_dir . mkdir ( ) log_jacobians_scale_dir = log_jacobians_dir / deformation_id log_jacobians_scale_dir . mkdir ( ) neg_jac_arr = _generate_deformation_fields ( reg_stage_dirs , resolutions , deformation_scale_dir , jacobians_scale_dir , log_jacobians_scale_dir , write_vectors , write_raw_jacobians , write_log_jacobians , threads = config [ 'threads' ] , filetype = config [ 'filetype' ] ) return neg_jac_arr
Generate jacobian determinants and optionaly defromation vectors
Parameters
Generate jacobian determinants and optionaly defromation vectors Parameters
"""
    Generate jacobian determinants and optionaly defromation vectors

    Parameters
    ----------
    config:
        LamaConfig object if running from other lama module
        Path to config file if running this module independently

    Notes
    -----
    How to generate the hacobian determinants is defined by the config['generate_deformation_fields'] entry.

    toml representation from the LAMA config:

    [generate_deformation_fields]
    192_to_10 = [ "deformable_192_to_10",]

    This will create a set of jacobian determinants and optional deformation fields called 192_to_10 and using the
    the named regisrtation stages in the list.

    Multiple sets of key/value pairs are allowed so that diffrent jacobians determinatnts might be made. For eaxmple
    you may want to include the affine transformation in the jacobians, which would look like so:

    affine_192_to_10 = [ "affine", "deformable_192_to_10"]

    Returns
    -------
    jacobian array if there are any negative values
    """ # Specify the resolutions from a stage to generate defs and jacs from # 1. We are spcifiying multiple lama-specified stages: Use the TransformParameters.O.txt from each stage # 2. It is one stage but we are using the elastix defined stages, which will be specified by ints #   Use TransformParameters.O.R<x>.txt files where x is the numbers specified # Just one stage is defined so use the TransformParameters.O.txt from that stage
config
Union[LamaConfig, dict]