- Load Data
# load the image and domain information
# requires input image file paths and phase encoding direction
data = DataObject('im1.nii.gz','im2.nii.gz',1, device=device)
- Correction Object
# set-up the objective function
# requires data object & regularization parameters
# optionally set linear operators, regularizer, preconditioning
loss_func = EPIMRIDistortionCorrection(data, alpha=300.0, beta=1e-4)
- Initialization
# initialize the field map
# see EPI_MRI.InitializationMethods for details
B0 = loss_func.initialize()
- Choose one of the following optimization methods:
- LBFGS
# set-up the optimizer
# requires correction object
# optionally maximum # of iterations, verbose flag, log file path
opt = LBFGS(loss_func, max_iter=200, verbose=True)
- Gauss Newton
# set-up the optimizer
# requires correction object
# optionally maximum # of GN iterations, linear solver,
# verbose flag, log file path
opt = GaussNewton(loss_func, max_iter=20, verbose=True)
- ADMM
# set-up the optimizer
# requires correction object
# optionally maximum # of iterations, verbose flag, log file path
loss_func_ADMM = EPIMRIDistortionCorrection(data, alpha=300.0, beta=1e-4, regularizer=myLaplacian1D, rho=1e3)
opt = ADMM(loss_func_ADMM, max_iter=20, verbose=True)
- Run Correction
# optimize!
opt.run_correction(B0)
- Apply Correction and Save Images
- Jacobian
# apply optimal field map to get corrected images
# field map and corrected image(s) will be saved
opt.apply_correction(method='jac')
- Least Squares
# apply optimal field map to get corrected images
# field map and corrected image(s) will be saved
opt.apply_correction(method='lstsq')
- Metrics
# calculate distance improvement and smoothness improvement
opt.evaluate_correction()
- Visualization
# show and save image of optimal field and corrected images
# can specify slice number and image intensity
opt.visualize()
- Log Files
- Optimization history automatically saved in {path}+log_file.txt
- Print full optimization history