Package: cgsense2023
CG-SENSE HOMEHomepageThis tutorialhttps://hdocmsu.github.io/cgsense2023/was written by
Hung Do based on theRRSG_Challenge_01github
repository.How to CiteAPA style:Do, H. (2024). CG-SENSE Tutorial version 0.0.3 (0.0.3). Zenodo.https://doi.org/10.5281/zenodo.10547817IEEE style:H. Do, “CG-SENSE Tutorial version 0.0.3”. Zenodo, Jan. 21, 2024. doi:
10.5281/zenodo.10547817.pip installThecgsense2023package was
uploaded toPyPIand can be easily installed using
the below command.pip install cgsense2023How to usePlot Modulefromcgsense2023.plotimport*importnumpyasnp# Sequential - full - spoke radial trajectorytraj_full=gen_radial_traj(golden=False,full_spoke=True)show_trajectory(traj_full,golden=True,figsize=(10,8))# golden - full - spoke radial trajectorytraj_full_golden=gen_radial_traj(golden=True,full_spoke=True)show_trajectory(traj_full_golden,golden=True,figsize=(10,8))Nim,Nx,Ny=12,128,256x1=np.random.randn(Nim,Nx,Ny)x2=np.random.randn(1,Nx,Ny)show_image_grid(x1)Warning: number of images (12) is larger than number of panels (2x5)!show_image_grid(x2)Metrics Modulefromcgsense2023.metricsimport*importnumpyasnp# same dimensionsNim,Nx,Ny=11,128,256x1=np.random.randn(1,Nx,Ny)x2=np.random.randn(1,Nx,Ny)print_metrics(x1,x2)+---------+-----------+
| Metrics |   Values  |
+---------+-----------+
|   MSE   | 1.999e+00 |
|   NMSE  | 2.000e+00 |
|   RMSE  | 1.414e+00 |
|  NRMSE  | 1.414e+00 |
|   PSNR  |   14.981  |
|   SSIM  | 0.0092604 |
+---------+-----------+Gridding Reconstructionfromcgsense2023.mathimport*fromcgsense2023.ioimport*importcgsense2023ascgs2003fromcgsense2023.mriimport*fromcgsense2023.optimizerimport*importh5pyimportnumpyasnpimportmatplotlib.pyplotaspltData Paths# path to the data filefpath='../testdata/rawdata_brain.h5'# path to the reference resultsrpath='../testdata/CG_reco_inscale_True_denscor_True_reduction_1.h5'withh5py.File(rpath,'r')asrf:print(list(rf.keys()))ref_cg=np.squeeze(rf['CG_reco'][()][-1])ref_grid=np.squeeze(rf['Coil_images'][()])['CG_reco', 'Coil_images']ref_cg.shape,ref_grid.shape((300, 300), (12, 300, 300))Setup Parameters# one stop shop for all Parameters and Dataparams=setup_params(fpath,R=1)['Coils', 'InScale', 'rawdata', 'trajectory']Setup MRI Operator# Set up MRI operatormrimodel=MriImagingModel(params)mriop=MriOperator(data_par=params["Data"],optimizer_par=params["Optimizer"])mriop.set_operator(mrimodel)# Single Coil images after FFTmy_grid=mriop.operator.NuFFT.adjoint(params['Data']['rawdata_density_cor'])my_grid.shape,ref_grid.shape((12, 300, 300), (12, 300, 300))# test gridding recon resultsnp.allclose(ref_grid,my_grid)True# test gridding recon resultsnp.array_equal(ref_grid,my_grid)Falseprint_metrics(np.abs(ref_grid[0]),np.abs(my_grid[0]))+---------+-----------+
| Metrics |   Values  |
+---------+-----------+
|   MSE   | 1.472e-24 |
|   NMSE  | 5.905e-15 |
|   RMSE  | 1.213e-12 |
|  NRMSE  | 7.684e-08 |
|   PSNR  |   154.87  |
|   SSIM  |    1.0    |
+---------+-----------+show_image_grid(my_grid,figsize=(10,10),rows=3,cols=4)show_image_grid(rss_rec(my_grid),figsize=(10,10))Gradient Descentguess=np.zeros((params['Data']['image_dim'],params['Data']['image_dim']))SD_result,SD_residuals,SD_ref_res=steepest_descent(mriop,guess,params['Data']['rawdata_density_cor'],iters=50,ref=ref_cg)Residuum at iter 50 : 6.553379e-06show_compared_images(np.abs(ref_cg),np.abs(SD_result),diff_fac=10,labels=['Reference','Steepest Descent','diff'])np.allclose(ref_cg,SD_result)Falseprint_metrics(np.abs(ref_cg),np.abs(SD_result))+---------+-----------+
| Metrics |   Values  |
+---------+-----------+
|   MSE   | 5.633e-14 |
|   NMSE  | 7.888e-05 |
|   RMSE  | 2.373e-07 |
|  NRMSE  | 8.882e-03 |
|   PSNR  |   55.242  |
|   SSIM  |   0.9988  |
+---------+-----------+CG’s Semi-Convergence BehaviorCG_result,CG_residuals,CG_ref_res=conjugate_gradient(mriop,guess,params['Data']['rawdata_density_cor'],iters=50,ref=ref_cg)Residuum at iter 50 : 2.993229e-06plt.plot(np.log10(SD_ref_res),'*--',label='SD reference_norms');plt.plot(np.log10(SD_residuals),'*--',label='SD residual_norms');plt.plot(np.log10(CG_ref_res),'*--',label='CG reference_norms');plt.plot(np.log10(CG_residuals),'*--',label='CG residual_norms');plt.grid();plt.xlabel("# iteration")plt.ylabel("residuals (log10)")plt.legend();Conjugate Gradient vs. REFBased on the “semi-convergence” plot above, the optimal number of
iterations for CG and SD are around 10 and 28, respectively.CG_result_vs_REF,_,_=conjugate_gradient(mriop,guess,params['Data']['rawdata_density_cor'],iters=10,ref=ref_cg)Residuum at iter 10 : 1.826174e-05show_compared_images(np.abs(ref_cg),np.abs(CG_result_vs_REF),diff_fac=200000,labels=['Reference','Conjugate Gradient','diff'])np.allclose(ref_cg,CG_result_vs_REF)Trueprint_metrics(np.abs(ref_cg),np.abs(CG_result_vs_REF))+---------+-----------+
| Metrics |   Values  |
+---------+-----------+
|   MSE   | 1.196e-22 |
|   NMSE  | 1.675e-13 |
|   RMSE  | 1.094e-11 |
|  NRMSE  | 4.093e-07 |
|   PSNR  |   141.97  |
|   SSIM  |    1.0    |
+---------+-----------+Developer installIf you want to developcgsense2023yourself, please use an editable
installation ofcgsense2023.git clone https://github.com/hdocmsu/cgsense2023.gitpip install -e "cgsense2023[dev]"You also need to use an editable installation ofnbdev,fastcore, andexecnb.Happy Coding!!!ReferencesThis template was created based on the below references. The list is not
exhaustive so if you notice any missing references, pleasereport an
issue. I will
promptly correct it.RRSG_Challenge_01github
repositoryfastMRIgithub
repositoryOriginal CG-SENSE Paper by Pruessmann et. al.,
2001CG-SENSE revisited: Results from the first ISMRM reproducibility
challengeDwight Nishimura, (Published Jan 10, 2010), “Principles of Magnetic
Resonance Imaging,” Stanford University, Palo Alto,
CAProf. James V. Burke’s Lecture on “The Conjugate Gradient
Algorithm”Magnetic Resonance Image Reconstruction: Theory, Methods, and
Applications,
(2022)sigPy github repoInvitation to ContributionsIf you would like to contribute to improve this repository please feel
freeto propose
here.LicenseMIT License as seen from theOriginal Repo’s
LicenseMIT LicenseCopyright (c) 2020 ISMRM Reproducible Research Study GroupPermission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
“Software”), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.