コード例 #1
0
def execute():
    import os, sys
    from mrtrix3 import app, path, run

    lut_input_path = 'LUT.txt'
    if not os.path.exists('LUT.txt'):
        gif3_home = os.environ.get('GIFDB_HOME', '')
        if not gif3_home:
            app.error(
                'Environment variable GIFDB_HOME is not set. Please set this variable manually, or provide script with path to file GIF3ColourLUT.txt using -lut option.'
            )
        lut_input_path = os.path.join(gif_home, 'GIF3ColourLUT.txt')
        if not os.path.isfile(lut_input_path):
            app.error(
                'Could not find GIF3 lookup table file (expected location: ' +
                lut_input_path + '), and none provided using -lut')

    if app.args.sgm_amyg_hipp:
        lut_output_file_name = 'GIF32ACT_sgm_amyg_hipp.txt'
    else:
        lut_output_file_name = 'GIF32ACT.txt'
    lut_output_path = os.path.join(path.sharedDataPath(),
                                   path.scriptSubDirName(),
                                   lut_output_file_name)
    if not os.path.isfile(lut_output_path):
        app.error(
            'Could not find lookup table file for converting GIF3 parcellation output to tissues (expected location: '
            + lut_output_path + ')')

    # Initial conversion from GIF3 parcellation to five principal tissue types
    run.command('labelconvert input.mif ' + lut_input_path + ' ' +
                lut_output_path + ' indices.mif')

    # Use mrcrop to reduce file size
    if app.args.nocrop:
        image = 'indices.mif'
    else:
        image = 'indices_cropped.mif'
        run.command(
            'mrthreshold indices.mif - -abs 0.5 | mrcrop indices.mif ' +
            image + ' -mask -')

    # Convert into the 5TT format for ACT
    run.command('mrcalc ' + image + ' 1 -eq cgm.mif')
    run.command('mrcalc ' + image + ' 2 -eq sgm.mif')
    run.command('mrcalc ' + image + ' 3 -eq  wm.mif')
    run.command('mrcalc ' + image + ' 4 -eq csf.mif')
    run.command('mrcalc ' + image + ' 5 -eq path.mif')

    run.command(
        'mrcat cgm.mif sgm.mif wm.mif csf.mif path.mif - -axis 3 | mrconvert - result.mif -datatype float32'
    )


# Created by Neil Oxtoby on 2018-03-02
# Modified from freesurfer.py in MRtrix3 v3.0
コード例 #2
0
def execute():
    import os, sys
    from mrtrix3 import app, path, run

    lut_input_path = 'LUT.txt'
    if not os.path.exists('LUT.txt'):
        freesurfer_home = os.environ.get('FREESURFER_HOME', '')
        if not freesurfer_home:
            app.error(
                'Environment variable FREESURFER_HOME is not set; please run appropriate FreeSurfer configuration script, set this variable manually, or provide script with path to file FreeSurferColorLUT.txt using -lut option'
            )
        lut_input_path = os.path.join(freesurfer_home,
                                      'FreeSurferColorLUT.txt')
        if not os.path.isfile(lut_input_path):
            app.error(
                'Could not find FreeSurfer lookup table file (expected location: '
                + freesurfer_lut + '), and none provided using -lut')

    if app.args.sgm_amyg_hipp:
        lut_output_file_name = 'FreeSurfer2ACT_sgm_amyg_hipp.txt'
    else:
        lut_output_file_name = 'FreeSurfer2ACT.txt'
    lut_output_path = os.path.join(path.sharedDataPath(),
                                   path.scriptSubDirName(),
                                   lut_output_file_name)
    if not os.path.isfile(lut_output_path):
        app.error(
            'Could not find lookup table file for converting FreeSurfer parcellation output to tissues (expected location: '
            + lut_output_path + ')')

    # Initial conversion from FreeSurfer parcellation to five principal tissue types
    run.command('labelconvert input.mif ' + lut_input_path + ' ' +
                lut_output_path + ' indices.mif')

    # Use mrcrop to reduce file size
    if app.args.nocrop:
        image = 'indices.mif'
    else:
        image = 'indices_cropped.mif'
        run.command(
            'mrthreshold indices.mif - -abs 0.5 | mrcrop indices.mif ' +
            image + ' -mask -')

    # Convert into the 5TT format for ACT
    run.command('mrcalc ' + image + ' 1 -eq cgm.mif')
    run.command('mrcalc ' + image + ' 2 -eq sgm.mif')
    run.command('mrcalc ' + image + ' 3 -eq  wm.mif')
    run.command('mrcalc ' + image + ' 4 -eq csf.mif')
    run.command('mrcalc ' + image + ' 5 -eq path.mif')

    run.command(
        'mrcat cgm.mif sgm.mif wm.mif csf.mif path.mif - -axis 3 | mrconvert - result.mif -datatype float32'
    )
コード例 #3
0
ファイル: freesurfer.py プロジェクト: MRtrix3/mrtrix3
def execute(): #pylint: disable=unused-variable
  import os.path #pylint: disable=unused-variable
  from mrtrix3 import app, path, run

  lut_input_path = 'LUT.txt'
  if not os.path.exists('LUT.txt'):
    freesurfer_home = os.environ.get('FREESURFER_HOME', '')
    if not freesurfer_home:
      app.error('Environment variable FREESURFER_HOME is not set; please run appropriate FreeSurfer configuration script, set this variable manually, or provide script with path to file FreeSurferColorLUT.txt using -lut option')
    lut_input_path = os.path.join(freesurfer_home, 'FreeSurferColorLUT.txt')
    if not os.path.isfile(lut_input_path):
      app.error('Could not find FreeSurfer lookup table file (expected location: ' + lut_input_path + '), and none provided using -lut')

  if app.args.sgm_amyg_hipp:
    lut_output_file_name = 'FreeSurfer2ACT_sgm_amyg_hipp.txt'
  else:
    lut_output_file_name = 'FreeSurfer2ACT.txt'
  lut_output_path = os.path.join(path.sharedDataPath(), path.scriptSubDirName(), lut_output_file_name)
  if not os.path.isfile(lut_output_path):
    app.error('Could not find lookup table file for converting FreeSurfer parcellation output to tissues (expected location: ' + lut_output_path + ')')

  # Initial conversion from FreeSurfer parcellation to five principal tissue types
  run.command('labelconvert input.mif ' + lut_input_path + ' ' + lut_output_path + ' indices.mif')

  # Use mrcrop to reduce file size
  if app.args.nocrop:
    image = 'indices.mif'
  else:
    image = 'indices_cropped.mif'
    run.command('mrthreshold indices.mif - -abs 0.5 | mrcrop indices.mif ' + image + ' -mask -')

  # Convert into the 5TT format for ACT
  run.command('mrcalc ' + image + ' 1 -eq cgm.mif')
  run.command('mrcalc ' + image + ' 2 -eq sgm.mif')
  run.command('mrcalc ' + image + ' 3 -eq  wm.mif')
  run.command('mrcalc ' + image + ' 4 -eq csf.mif')
  run.command('mrcalc ' + image + ' 5 -eq path.mif')

  run.command('mrcat cgm.mif sgm.mif wm.mif csf.mif path.mif - -axis 3 | mrconvert - result.mif -datatype float32')