lama/elastix/reverse_registration.py
def modify_elx_parameter_file(elx_param_file: Path, newfile_name: str, replacements: Dict):
    """
    Modifies the elastix input parameter file that was used in the original transformation.
    Turns off writing the image results at the end as we only need an inverted output file.
    Also changes interpolation order in the case of inverting labels

    Parameters
    ----------
    elx_param_file
        path to elastix input parameter file
    newfile_name
        path to save modified parameter file to
    replacements


    """

    try:
        with open(elx_param_file) as old, open(newfile_name, "w") as new:

            for line in old:
                if line.startswith('(WriteResultImage '):
                    line = '(WriteResultImage "false")\n'
                if line.startswith('WriteResultImageAfterEachResolution '):
                   continue
                try:
                    param_name = line.split()[0][1:]
                except IndexError:
                    continue  # comment?

                if param_name in replacements:
                    value = replacements[param_name]
                    try:
                        int(value)
                    except ValueError:
                        # Not an int, neeed quotes
                        line = '({} "{}")\n'.format(param_name, value)
                    else:
                        # An int, no quotes
                        line = '({} {})\n'.format(param_name, value)
                new.write(line)
    except IOError as e:
        logging.error("Error modifying the elastix parameter file: {}".format(e))
        return False
    return True

    Modifies the elastix input parameter file that was used in the original transformation.
    Turns off writing the image results at the end as we only need an inverted output file.
    Also changes interpolation order in the case of inverting labels

    Parameters
    ----------
    elx_param_file
        path to elastix input parameter file
    newfile_name
        path to save modified parameter file to
    replacements


    
Modifies the elastix input parameter file that was used in the original transformation.
Turns off writing the image results at the end as we only need an inverted output file.
Also changes interpolation order in the case of inverting labels

Parameters

elx_param_file
path to elastix input parameter file
newfile_name
path to save modified parameter file to
replacements
Modifies the elastix input parameter file that was used in the original transformation . Turns off writing the image results at the end as we only need an inverted output file . Also changes interpolation order in the case of inverting labels Parameters elx_param_file path to elastix input parameter file newfile_name path to save modified parameter file to replacements
def modify_elx_parameter_file(elx_param_file: Path, newfile_name: str, replacements: Dict):
    try:
        with open(elx_param_file) as old, open(newfile_name, "w") as new:
            for line in old:
                if line.startswith('(WriteResultImage '):
                    line = '(WriteResultImage "false")\n'
                if line.startswith('WriteResultImageAfterEachResolution '):
                   continue
                try:
                    param_name = line.split()[0][1:]
                except IndexError:
                    continue  
                if param_name in replacements:
                    value = replacements[param_name]
                    try:
                        int(value)
                    except ValueError:
                        line = '({} "{}")\n'.format(param_name, value)
                    else:
                        line = '({} {})\n'.format(param_name, value)
                new.write(line)
    except IOError as e:
        logging.error("Error modifying the elastix parameter file: {}".format(e))
        return False
    return True
def modify_elx_parameter_file ( elx_param_file : Path , newfile_name : str , replacements : Dict ) : try : with open ( elx_param_file ) as old , open ( newfile_name , "w" ) as new : for line in old : if line . startswith ( '(WriteResultImage ' ) : line = '(WriteResultImage "false")\n' if line . startswith ( 'WriteResultImageAfterEachResolution ' ) : continue try : param_name = line . split ( ) [ 0 ] [ 1 : ] except IndexError : continue if param_name in replacements : value = replacements [ param_name ] try : int ( value ) except ValueError : line = '({} "{}")\n' . format ( param_name , value ) else : line = '({} {})\n' . format ( param_name , value ) new . write ( line ) except IOError as e : logging . error ( "Error modifying the elastix parameter file: {}" . format ( e ) ) return False return True
Modifies the elastix input parameter file that was used in the original transformation.
Modifies the elastix input parameter file that was used in the original transformation .
"""
    Modifies the elastix input parameter file that was used in the original transformation.
    Turns off writing the image results at the end as we only need an inverted output file.
    Also changes interpolation order in the case of inverting labels

    Parameters
    ----------
    elx_param_file
        path to elastix input parameter file
    newfile_name
        path to save modified parameter file to
    replacements


    """ # comment? # Not an int, neeed quotes # An int, no quotes
elx_param_file
Path
newfile_name
str
replacements
Dict