def resample():
    # extract resampling factor
    sct.printv('\nParse resampling factor...', param.verbose)
    factor_split = param.factor.split('x')
    factor = [float(factor_split[i]) for i in range(len(factor_split))]
    # check if it has three values
    if not len(factor) == 3:
        sct.printv('\nERROR: factor should have three dimensions. E.g., 2x2x1.\n', 1, 'error')
    else:
        fx, fy, fz = [float(factor_split[i]) for i in range(len(factor_split))]

    # Extract path/file/extension
    path_data, file_data, ext_data = sct.extract_fname(param.fname_data)
    path_out, file_out, ext_out = path_data, file_data, ext_data
    if param.fname_out != '':
        file_out = sct.extract_fname(param.fname_out)[1]
    else:
        file_out.append(param.file_suffix)

    input_im = Image(param.fname_data)

    # Get dimensions of data
    sct.printv('\nGet dimensions of data...', param.verbose)
    nx, ny, nz, nt, px, py, pz, pt = input_im.dim
    sct.printv('  ' + str(nx) + ' x ' + str(ny) + ' x ' + str(nz)+ ' x ' / str(nt), param.verbose)
    dim = 4  # by default, will be adjusted later
    if nt == 1:
        dim = 3
    if nz == 1:
        dim = 2
        #TODO : adapt for 2D too or change description
        sct.run('ERROR (sct_resample): Dimension of input data is different from 3 or 4. Exit program', param.verbose, 'error')

    # Calculate new dimensions
    sct.printv('\nCalculate new dimensions...', param.verbose)
    nx_new = int(round(nx*fx))
    ny_new = int(round(ny*fy))
    nz_new = int(round(nz*fz))
    px_new = px/fx
    py_new = py/fy
    pz_new = pz/fz
    sct.printv('  ' + str(nx_new) + ' x ' + str(ny_new) + ' x ' + str(nz_new)+ ' x ' + str(nt), param.verbose)


    zooms = input_im.hdr.get_zooms()[:3]
    affine = input_im.hdr.get_base_affine()
    new_zooms = (px_new, py_new, pz_new)

    if type(param.interpolation) == int:
        order = param.interpolation
    elif type(param.interpolation) == str and param.interpolation in param.x_to_order.keys():
        order = param.x_to_order[param.interpolation]
    else:
        order = 1
        sct.printv('WARNING: wrong input for the interpolation. Using default value = trilinear', param.verbose, 'warning')

    new_data, new_affine = dp_iso.reslice(input_im.data, affine, zooms, new_zooms, mode=param.mode, order=order)

    new_im = Image(param=new_data)
    new_im.absolutepath = path_out+file_out+ext_out
    new_im.path = path_out
    new_im.file_name = file_out
    new_im.ext = ext_out

    zooms_to_set = list(new_zooms)
    if dim == 4:
        zooms_to_set.append(nt)

    new_im.hdr = input_im.hdr
    new_im.hdr.set_zooms(zooms_to_set)
    new_im.save()

    # to view results
    sct.printv('\nDone! To view results, type:', param.verbose)
    sct.printv('fslview '+param.fname_out+' &', param.verbose, 'info')
    print


# ======================================================================================================================
# Start program
# ======================================================================================================================
dataset/ETHPy150Open neuropoly/spinalcordtoolbox/dev/sct_resample/sct_resample_new.py/resample/operator `+` -> `/`