def main():
    # create temporary folder
    sct.printv('\nCreate temporary folder...', verbose, 'normal')
    path_tmp = 'tmp.'+time.strftime("%y%m%d%H%M%S")+'/'
    sct.run('mkdir '+path_tmp)

    target = 'target.nii.gz'
    target_seg = 'target_seg.nii.gz'
    anat = 'anat.nii.gz'
    anat_seg = 'anat_seg.nii.gz'
    warp_template2anat = 'warp_template2anat.nii.gz'

    sct.run('cp '+multimodal_reg_param.anat+' '+path_tmp+anat)
    sct.run('cp '+multimodal_reg_param.target+' '+path_tmp+target)
    sct.run('cp '+multimodal_reg_param.anat_seg+' '+path_tmp+anat_seg)
    sct.run('cp '+multimodal_reg_param.target_seg+' '+path_tmp+target_seg)
    sct.run('cp '+multimodal_reg_param.warp_template2anat+' '+path_tmp+warp_template2anat)

    os.chdir(path_tmp)
    # registration of the template to the target
    warp_anat2target, warp_target2anat, label_original = reg_multimodal_warp(anat, target, anat_seg, target_seg, warp_template2anat, multimodal_reg_param)

    # segmentation of the gray matter
    gm_seg_param.res_type = 'binary'
    wm_fname, gm_fname = segment_gm(target_fname=target, sc_seg_fname=target_seg, path_to_label=label_original, param=gm_seg_param)
    wm_seg_out = sct.extract_fname(multimodal_reg_param.target)[1]+'_wm_seg.nii.gz'
    gm_seg_out = sct.extract_fname(multimodal_reg_param.target)[1]+'_gm_seg.nii.gz'
    sct.run('cp '+wm_fname+' ../'+wm_seg_out)
    sct.run('cp '+gm_fname+' ../'+gm_seg_out)

    # registration of the template WM to the automatic Wm segmentation
    wm_reg_param.fname_fixed = wm_fname
    wm_reg_param.fname_moving = label_original + '/template/MNI-Poly-AMU_WM.nii.gz'
    wm_reg_param.fname_seg_fixed = target_seg
    wm_reg_param.fname_seg_moving = label_original + '/template/MNI-Poly-AMU_cord.nii.gz'

    if gm_seg_param.res_type == 'binary':
        # binarize template WM
        template_wm = Image(wm_reg_param.fname_moving)
        template_wm.data = (template_wm.data > 0.5).astype(int)
        template_wm.save()

    warp, inverse_warp = wm_registration(wm_reg_param)

    warp_anat2target_corrected = 'warp_'+sct.extract_fname(multimodal_reg_param.anat)[1]+'2'+sct.extract_fname(multimodal_reg_param.target)[1]+'_corrected_wm.nii.gz'
    warp_target2anat_corrected = 'warp_'+sct.extract_fname(multimodal_reg_param.target)[1]+'2'+sct.extract_fname(multimodal_reg_param.anat)[1]+'_corrected_wm.nii.gz'

    sct.run('sct_concat_transfo -w '+warp_anat2target+','+warp+' -d '+target+' -o '+warp_anat2target_corrected)
    sct.run('sct_concat_transfo -w '+inverse_warp+','+warp_target2anat+' -d '+anat+' -o '+warp_target2anat_corrected)

    target_reg = sct.extract_fname(multimodal_reg_param.target)[1]+'_reg_corrected.nii.gz'
    anat_reg = sct.extract_fname(multimodal_reg_param.anat)[1]+'_reg_corrected.nii.gz'
    sct.run('sct_apply_transfo -i '+target+' -d '+anat+' -w '+warp_target2anat_corrected+' -o '+target_reg)
    sct.run('sct_apply_transfo -i '+anat+' -d '+target+' -w '+warp_anat2target_corrected+' -o '+anat_reg)

    sct.run('cp '+target_reg+' ../'+target_reg)
    sct.run('cp '+anat_reg+' ../'+anat_reg)
    sct.run('cp '+warp_anat2target_corrected+' ../'+warp_anat2target_corrected)
    sct.run('cp '+warp_target2anat_corrected+' ../'+warp_target2anat_corrected)

    sct.printv('Done!\n'
               'You can warp the template to the target using the following command lines:\n'
               'sct_concat_transfo -w '+multimodal_reg_param.warp_template2anat+','+warp_anat2target_corrected+' -d '+multimodal_reg_param.target+' -o warp_template2'+sct.extract_fname(multimodal_reg_param.target)[1]+'.nii.gz\n'
               'sct_warp_template -d '+multimodal_reg_param.target+' -w warp_template2'+sct.extract_fname(multimodal_reg_param.target)[1]+'.nii.gz', verbose, 'info')
    os.chdir('..')

    if remove:
        sct.printv('\nRemove temporary files...', verbose, 'normal')
        sct.run("rm -rf "+path_tmp)
dataset/ETHPy150Open neuropoly/spinalcordtoolbox/dev/sct_register_graymatter/sct_register_graymatter.py/main/original