def register_slicewise(fname_src,
                        fname_dest,
                        fname_mask='',
                        warp_forward_out='step0Warp.nii.gz',
                        warp_inverse_out='step0InverseWarp.nii.gz',
                        paramreg=None,
                        ants_registration_params=None,
                        verbose=0):

    # create temporary folder
    sct.printv('\nCreate temporary folder...', verbose)
    path_tmp = sct.tmp_create(verbose)

    # copy data to temp folder
    sct.printv('\nCopy input data to temp folder...', verbose)
    convert(fname_src, path_tmp+'src.nii')
    convert(fname_dest, path_tmp+'dest.nii')
    if fname_mask != '':
        convert(fname_mask, path_tmp+'mask.nii.gz')

    # go to temporary folder
    chdir(path_tmp)

    # Calculate displacement
    if paramreg.algo == 'centermass':
        # calculate translation of center of mass between source and destination in voxel space
        register2d_centermass('src.nii', 'dest.nii', fname_warp=warp_forward_out, fname_warp_inv=warp_inverse_out, verbose=verbose)
    else:
        # convert SCT flags into ANTs-compatible flags
        algo_dic = {'translation': 'Translation', 'rigid': 'Rigid', 'affine': 'Affine', 'syn': 'SyN', 'bsplinesyn': 'BSplineSyN', 'centermass': 'centermass'}
        paramreg.algo = algo_dic[paramreg.algo]
        # run slicewise registration
        register2d('src.nii', 'dest.nii', fname_mask=fname_mask, fname_warp=warp_forward_out, fname_warp_inv=warp_inverse_out, paramreg=paramreg, ants_registration_params=ants_registration_params, verbose=verbose)

    sct.printv('\nMove warping fields to parent folder...', verbose)
    sct.run('mv '+warp_forward_out+' ../')
    sct.run('mv '+warp_inverse_out+' ../')

    # go back to parent folder
    chdir('../')
dataset/ETHPy150Open neuropoly/spinalcordtoolbox/scripts/msct_register.py/register_slicewise/original