lama/elastix/deformations.py
def _generate_deformation_fields(registration_dirs: List,
                                 resolutions: List,
                                 deformation_dir: Path,
                                 jacobian_dir: Path,
                                 log_jacobians_dir: Path,
                                 write_vectors: bool,
                                 write_raw_jacobians: bool,
                                 write_log_jacobians: bool,
                                 threads=None,
                                 filetype='nrrd',
                                 jacmat=False):
    """
    Run transformix on the specified registration stage to generate deformation fields and spatial jacobians
    """
    logging.info('### Generating deformation files ###')

    specimen_list = [x for x in registration_dirs[0].iterdir() if (registration_dirs[0] / x).is_dir()]

    # if len(specimen_list) < 1:
    #     logging.warn('Can't find any )

    for specimen_path in specimen_list:
        specimen_id = specimen_path.name
        temp_transform_files_dir = deformation_dir / specimen_id
        temp_transform_files_dir.mkdir(exist_ok=True)

        transform_params = []
        # Get the transform parameters for the subsequent registrations

        if len(resolutions) == 0:  # Use the whole stages by using the joint transform file

            for reg_dir in registration_dirs:
                single_reg_dir = reg_dir / specimen_id
                elastix_tform_file = single_reg_dir / ELX_TFORM_NAME  # Transform file in the registration directory

                if not os.path.isfile(elastix_tform_file):
                    raise FileNotFoundError(f"Error. Cannot find elastix transform parameter file: {elastix_tform_file}")

                # Create a new path to copy the transform file to. Then it's in the same forlder as the jacobians etc
                temp_transform_file = temp_transform_files_dir / f'{reg_dir.name}_{specimen_id}_{elastix_tform_file.name}'

                shutil.copy(elastix_tform_file, temp_transform_file)
                transform_params.append(temp_transform_file)
            _chain_tforms(transform_params)  # Add the InitialtransformParamtere line

        else:
            # The resolutdeformation_dirion paramter files are numbered from 0 but the config counts from 1
            for i in resolutions:
                i -= 1
                single_reg_dir = registration_dirs[0] / specimen_id
                elastix_tform_file = single_reg_dir / ELX_TFORM_NAME_RESOLUTION.format(i)

                if not os.path.isfile(elastix_tform_file):
                    raise FileNotFoundError(f"### Error. Cannot find elastix transform parameter file: {elastix_tform_file}")

                temp_transform_file = temp_transform_files_dir / (registration_dirs[0].name + '_' + elastix_tform_file.name)

                shutil.copy(elastix_tform_file, temp_transform_file)
                transform_params.append(temp_transform_file)

            _chain_tforms(transform_params)  # Add the InitialtransformParamtere line

        # Copy the tp files into the temp directory and then modify to add initail transform

        # pass in the last tp file [-1] as the other tp files are internally referenced withinn this file
        neg_jac_array = _get_deformations(transform_params[-1], deformation_dir, jacobian_dir, log_jacobians_dir, filetype, specimen_id,
                                          threads, jacmat, write_vectors, write_raw_jacobians, write_log_jacobians)
        return neg_jac_array

    Run transformix on the specified registration stage to generate deformation fields and spatial jacobians
    
Run transformix on the specified registration stage to generate deformation fields and spatial jacobians
Run transformix on the specified registration stage to generate deformation fields and spatial jacobians
def _generate_deformation_fields(registration_dirs: List,
                                 resolutions: List,
                                 deformation_dir: Path,
                                 jacobian_dir: Path,
                                 log_jacobians_dir: Path,
                                 write_vectors: bool,
                                 write_raw_jacobians: bool,
                                 write_log_jacobians: bool,
                                 threads=None,
                                 filetype='nrrd',
                                 jacmat=False):
    logging.info('### Generating deformation files ###')
    specimen_list = [x for x in registration_dirs[0].iterdir() if (registration_dirs[0] / x).is_dir()]
    for specimen_path in specimen_list:
        specimen_id = specimen_path.name
        temp_transform_files_dir = deformation_dir / specimen_id
        temp_transform_files_dir.mkdir(exist_ok=True)
        transform_params = []
        if len(resolutions) == 0:  
            for reg_dir in registration_dirs:
                single_reg_dir = reg_dir / specimen_id
                elastix_tform_file = single_reg_dir / ELX_TFORM_NAME  
                if not os.path.isfile(elastix_tform_file):
                    raise FileNotFoundError(f"Error. Cannot find elastix transform parameter file: {elastix_tform_file}")
                temp_transform_file = temp_transform_files_dir / f'{reg_dir.name}_{specimen_id}_{elastix_tform_file.name}'
                shutil.copy(elastix_tform_file, temp_transform_file)
                transform_params.append(temp_transform_file)
            _chain_tforms(transform_params)  
        else:
            for i in resolutions:
                i -= 1
                single_reg_dir = registration_dirs[0] / specimen_id
                elastix_tform_file = single_reg_dir / ELX_TFORM_NAME_RESOLUTION.format(i)
                if not os.path.isfile(elastix_tform_file):
                    raise FileNotFoundError(f"### Error. Cannot find elastix transform parameter file: {elastix_tform_file}")
                temp_transform_file = temp_transform_files_dir / (registration_dirs[0].name + '_' + elastix_tform_file.name)
                shutil.copy(elastix_tform_file, temp_transform_file)
                transform_params.append(temp_transform_file)
            _chain_tforms(transform_params)  
        neg_jac_array = _get_deformations(transform_params[-1], deformation_dir, jacobian_dir, log_jacobians_dir, filetype, specimen_id,
                                          threads, jacmat, write_vectors, write_raw_jacobians, write_log_jacobians)
        return neg_jac_array
def _generate_deformation_fields ( registration_dirs : List , resolutions : List , deformation_dir : Path , jacobian_dir : Path , log_jacobians_dir : Path , write_vectors : bool , write_raw_jacobians : bool , write_log_jacobians : bool , threads = None , filetype = 'nrrd' , jacmat = False ) : logging . info ( '### Generating deformation files ###' ) specimen_list = [ x for x in registration_dirs [ 0 ] . iterdir ( ) if ( registration_dirs [ 0 ] / x ) . is_dir ( ) ] for specimen_path in specimen_list : specimen_id = specimen_path . name temp_transform_files_dir = deformation_dir / specimen_id temp_transform_files_dir . mkdir ( exist_ok = True ) transform_params = [ ] if len ( resolutions ) == 0 : for reg_dir in registration_dirs : single_reg_dir = reg_dir / specimen_id elastix_tform_file = single_reg_dir / ELX_TFORM_NAME if not os . path . isfile ( elastix_tform_file ) : raise FileNotFoundError ( f"Error. Cannot find elastix transform parameter file: {elastix_tform_file}" ) temp_transform_file = temp_transform_files_dir / f'{reg_dir.name}_{specimen_id}_{elastix_tform_file.name}' shutil . copy ( elastix_tform_file , temp_transform_file ) transform_params . append ( temp_transform_file ) _chain_tforms ( transform_params ) else : for i in resolutions : i -= 1 single_reg_dir = registration_dirs [ 0 ] / specimen_id elastix_tform_file = single_reg_dir / ELX_TFORM_NAME_RESOLUTION . format ( i ) if not os . path . isfile ( elastix_tform_file ) : raise FileNotFoundError ( f"### Error. Cannot find elastix transform parameter file: {elastix_tform_file}" ) temp_transform_file = temp_transform_files_dir / ( registration_dirs [ 0 ] . name + '_' + elastix_tform_file . name ) shutil . copy ( elastix_tform_file , temp_transform_file ) transform_params . append ( temp_transform_file ) _chain_tforms ( transform_params ) neg_jac_array = _get_deformations ( transform_params [ - 1 ] , deformation_dir , jacobian_dir , log_jacobians_dir , filetype , specimen_id , threads , jacmat , write_vectors , write_raw_jacobians , write_log_jacobians ) return neg_jac_array
Run transformix on the specified registration stage to generate deformation fields and spatial jacobians
Run transformix on the specified registration stage to generate deformation fields and spatial jacobians
"""
    Run transformix on the specified registration stage to generate deformation fields and spatial jacobians
    """ # if len(specimen_list) < 1: #     logging.warn('Can't find any ) # Get the transform parameters for the subsequent registrations # Use the whole stages by using the joint transform file # Transform file in the registration directory # Create a new path to copy the transform file to. Then it's in the same forlder as the jacobians etc # Add the InitialtransformParamtere line # The resolutdeformation_dirion paramter files are numbered from 0 but the config counts from 1 # Add the InitialtransformParamtere line # Copy the tp files into the temp directory and then modify to add initail transform # pass in the last tp file [-1] as the other tp files are internally referenced withinn this file
registration_dirs
List
resolutions
List
deformation_dir
Path
jacobian_dir
Path
log_jacobians_dir
Path
write_vectors
bool
write_raw_jacobians
bool
write_log_jacobians
bool
threads
filetype
jacmat