lama/elastix/invert_transforms.py
def make_elastix_inversion_parameter_file(elx_param_file: Path, newfile_name: str, replacements: Dict):
    """
    Modifies the elastix input parameter file that was used in the original transformation.
    Adds DisplacementMagnitudePenalty (which is needed for inverting)
    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: str
        path to elastix input parameter file
    newfile_name: str
        path to save modified parameter file to

    """

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

            for line in old:
                if line.startswith("(Metric "):
                    line = '(Metric "DisplacementMagnitudePenalty")\n'
                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.
    Adds DisplacementMagnitudePenalty (which is needed for inverting)
    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: str
        path to elastix input parameter file
    newfile_name: str
        path to save modified parameter file to

    
Modifies the elastix input parameter file that was used in the original transformation.
Adds DisplacementMagnitudePenalty (which is needed for inverting)
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

str
path to elastix input parameter file
newfile_name: str
path to save modified parameter file to
Modifies the elastix input parameter file that was used in the original transformation . Adds DisplacementMagnitudePenalty ( which is needed for inverting ) 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 str path to elastix input parameter file newfile_name : str path to save modified parameter file to
def make_elastix_inversion_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("(Metric "):
                    line = '(Metric "DisplacementMagnitudePenalty")\n'
                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 make_elastix_inversion_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 ( "(Metric " ) : line = '(Metric "DisplacementMagnitudePenalty")\n' 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.
    Adds DisplacementMagnitudePenalty (which is needed for inverting)
    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: str
        path to elastix input parameter file
    newfile_name: str
        path to save modified parameter file to

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