lama/elastix/invert_transforms.py
def _invert_transform_parameters(args: Dict):
    """
    Generate a single inverted elastix transform parameter file. This can then be used to invert labels, masks etc.
    If any of the step fail, return as subsequent steps will also fail. The logging of failures is handled
    within each function
    """

    # If we have both the image and label inverted transforms, don't do anything if noclobber is True
    clobber = args['clobber']
    threads = args['threads']

    image_transform_param_path = abspath(join(args['specimen_stage_inversion_dir'], args['image_transform_file']))
    label_transform_param_path = abspath(join(args['specimen_stage_inversion_dir'], args['label_transform_file']))

    if not clobber and isfile(label_transform_param_path) and isfile(image_transform_param_path):
        logging.info('skipping {} as noclobber is True and inverted parameter files exist')
        return

    # Modify the elastix registration input parameter file to enable inversion (Change metric and don't write image results)
    inversion_params = abspath(join(args['specimen_stage_inversion_dir'], args['param_file_output_name'])) # The elastix registration parameters used for inversion
    make_elastix_inversion_parameter_file(abspath(args['parameter_file']), inversion_params, args['image_replacements'])  # I don't think we need the replacements here!!!!!!!!

     # Do the inversion, making the inverted TransformParameters file
    fixed_vol = args['fixed_volume']
    forward_tform_file = abspath(args['transform_file'])
    invert_param_dir = args['specimen_stage_inversion_dir']

    if not invert_elastix_transform_parameters(fixed_vol, forward_tform_file, inversion_params, invert_param_dir, threads):
        return

    # Get the resulting TransformParameters file, and create a transform file suitable for inverting normal volumes
    image_inverted_tform = abspath(join(args['specimen_stage_inversion_dir'], 'TransformParameters.0.txt'))

    if not _modify_inverted_tform_file(image_inverted_tform, image_transform_param_path):
        return

    # Get the resulting TransformParameters file, and create a transform file suitable for inverting label volumes

    # replace the parameter in the image file with label-specific parameters and save in new file. No need to
    # generate one from scratch
    if not make_elastix_inversion_parameter_file(image_transform_param_path, label_transform_param_path, args['label_replacements']):
        return

    _modify_inverted_tform_file(label_transform_param_path)

    Generate a single inverted elastix transform parameter file. This can then be used to invert labels, masks etc.
    If any of the step fail, return as subsequent steps will also fail. The logging of failures is handled
    within each function
    
Generate a single inverted elastix transform parameter file. This can then be used to invert labels, masks etc.
If any of the step fail, return as subsequent steps will also fail. The logging of failures is handled
within each function
Generate a single inverted elastix transform parameter file . This can then be used to invert labels masks etc . If any of the step fail return as subsequent steps will also fail . The logging of failures is handled within each function
def _invert_transform_parameters(args: Dict):
    clobber = args['clobber']
    threads = args['threads']
    image_transform_param_path = abspath(join(args['specimen_stage_inversion_dir'], args['image_transform_file']))
    label_transform_param_path = abspath(join(args['specimen_stage_inversion_dir'], args['label_transform_file']))
    if not clobber and isfile(label_transform_param_path) and isfile(image_transform_param_path):
        logging.info('skipping {} as noclobber is True and inverted parameter files exist')
        return
    inversion_params = abspath(join(args['specimen_stage_inversion_dir'], args['param_file_output_name'])) 
    make_elastix_inversion_parameter_file(abspath(args['parameter_file']), inversion_params, args['image_replacements'])  
    fixed_vol = args['fixed_volume']
    forward_tform_file = abspath(args['transform_file'])
    invert_param_dir = args['specimen_stage_inversion_dir']
    if not invert_elastix_transform_parameters(fixed_vol, forward_tform_file, inversion_params, invert_param_dir, threads):
        return
    image_inverted_tform = abspath(join(args['specimen_stage_inversion_dir'], 'TransformParameters.0.txt'))
    if not _modify_inverted_tform_file(image_inverted_tform, image_transform_param_path):
        return
    if not make_elastix_inversion_parameter_file(image_transform_param_path, label_transform_param_path, args['label_replacements']):
        return
    _modify_inverted_tform_file(label_transform_param_path)
def _invert_transform_parameters ( args : Dict ) : clobber = args [ 'clobber' ] threads = args [ 'threads' ] image_transform_param_path = abspath ( join ( args [ 'specimen_stage_inversion_dir' ] , args [ 'image_transform_file' ] ) ) label_transform_param_path = abspath ( join ( args [ 'specimen_stage_inversion_dir' ] , args [ 'label_transform_file' ] ) ) if not clobber and isfile ( label_transform_param_path ) and isfile ( image_transform_param_path ) : logging . info ( 'skipping {} as noclobber is True and inverted parameter files exist' ) return inversion_params = abspath ( join ( args [ 'specimen_stage_inversion_dir' ] , args [ 'param_file_output_name' ] ) ) make_elastix_inversion_parameter_file ( abspath ( args [ 'parameter_file' ] ) , inversion_params , args [ 'image_replacements' ] ) fixed_vol = args [ 'fixed_volume' ] forward_tform_file = abspath ( args [ 'transform_file' ] ) invert_param_dir = args [ 'specimen_stage_inversion_dir' ] if not invert_elastix_transform_parameters ( fixed_vol , forward_tform_file , inversion_params , invert_param_dir , threads ) : return image_inverted_tform = abspath ( join ( args [ 'specimen_stage_inversion_dir' ] , 'TransformParameters.0.txt' ) ) if not _modify_inverted_tform_file ( image_inverted_tform , image_transform_param_path ) : return if not make_elastix_inversion_parameter_file ( image_transform_param_path , label_transform_param_path , args [ 'label_replacements' ] ) : return _modify_inverted_tform_file ( label_transform_param_path )
Generate a single inverted elastix transform parameter file.
Generate a single inverted elastix transform parameter file .
"""
    Generate a single inverted elastix transform parameter file. This can then be used to invert labels, masks etc.
    If any of the step fail, return as subsequent steps will also fail. The logging of failures is handled
    within each function
    """ # If we have both the image and label inverted transforms, don't do anything if noclobber is True # Modify the elastix registration input parameter file to enable inversion (Change metric and don't write image results) # The elastix registration parameters used for inversion # I don't think we need the replacements here!!!!!!!! # Do the inversion, making the inverted TransformParameters file # Get the resulting TransformParameters file, and create a transform file suitable for inverting normal volumes # Get the resulting TransformParameters file, and create a transform file suitable for inverting label volumes # replace the parameter in the image file with label-specific parameters and save in new file. No need to # generate one from scratch
args
Dict