From ee1ca0ccde7f7e20de949e4692fe7a43f7744143 Mon Sep 17 00:00:00 2001 From: ElinaPetersson Date: Wed, 25 Mar 2026 09:56:15 +0100 Subject: [PATCH 1/3] first attempt at degibbs script --- tests/IVIMpreproc/unit_tests/test_degibbs.py | 81 ++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 tests/IVIMpreproc/unit_tests/test_degibbs.py diff --git a/tests/IVIMpreproc/unit_tests/test_degibbs.py b/tests/IVIMpreproc/unit_tests/test_degibbs.py new file mode 100644 index 0000000..656d36b --- /dev/null +++ b/tests/IVIMpreproc/unit_tests/test_degibbs.py @@ -0,0 +1,81 @@ +''' +Not done! Need a better metric than just noise correlation + +''' +# %% +from phantoms.brain.sim_brain_phantom_preproc import simulate_brain_phantom + +simulate_brain_phantom(snr = 50) +#%% +import nibabel as nib +import numpy as np +from src.original.EP_GU.brain_pipeline import degibbs_wrap +import matplotlib.pyplot as plt +import os + +# load brain phantom +S_ref = nib.load('phantoms/brain/data/diffusive_reference_relax.nii.gz').get_fdata() + +# Convert to k-space +S_k = np.fft.fftn(S_ref,axes=(0,1)) +S_k = np.fft.fftshift(S_k,axes=(0,1)) + +plt.subplot(1,2,1) +plt.imshow(np.log(np.abs(S_k[:,:,30,0])+1),cmap='gray') +plt.xticks([]) +plt.yticks([]) + +# Crop k-space +S_k[:10,:,:,:] = 0 +S_k[-10:,:,:,:] = 0 +# S_k[:,:10,:,:] = 0 +# S_k[:,-10:,:,:] = 0 + +# Test plot +plt.subplot(1,2,2) +plt.imshow(np.log(np.abs(S_k[:,:,30,0])+1),cmap='gray') +plt.xticks([]) +plt.yticks([]) +plt.show() + +# Inverse Fourier transform +S_crop = np.fft.ifftshift(S_k,axes=(0,1)) +S_crop = np.fft.ifftn(S_crop,axes=(0,1)).real + +# Save image +S_crop_nii = nib.Nifti1Image(S_crop.astype(np.float32),np.eye(4)) +S_crop_file = 'phantoms/brain/data/diffusive_reference_relax_cropped.nii.gz' +nib.save(S_crop_nii,S_crop_file) + +# Apply degibbs +S_degibbs_file = degibbs_wrap(S_crop_file) + +# Plot results +S_degibbs = nib.load(S_degibbs_file).get_fdata() +plt.subplot(1,3,1) +plt.imshow(np.rot90(S_ref[:,:,30,0]),cmap='gray') +plt.xticks([]) +plt.yticks([]) +plt.subplot(1,3,2) +plt.imshow(np.rot90(S_crop[:,:,30,0]),cmap='gray') +plt.xticks([]) +plt.yticks([]) +plt.subplot(1,3,3) +plt.imshow(np.rot90(S_degibbs[:,:,30,0]),cmap='gray') +plt.xticks([]) +plt.yticks([]) +plt.show() + +mask = nib.load(os.path.join('phantoms','brain','data','diffusive_snr50_relax_mask.nii.gz')).get_fdata() + +def noise_correlation(img): + img = img - np.mean(img) + return np.sum(img[:, :-1] * img[:, 1:]) / np.sum(img**2) + +S_crop = nib.load(S_crop_file).get_fdata() +S_degibbs = nib.load(S_degibbs_file).get_fdata() +S_crop[mask==0,:]=0 +S_degibbs[mask==0,:]=0 + +print('Noise correlation before degibbs: {}'.format(noise_correlation(S_crop))) +print('Noise correlation after degibbs: {}'.format(noise_correlation(S_degibbs))) \ No newline at end of file From bc77b44c6231dc01410e7ee9c9dad7c7243b5b88 Mon Sep 17 00:00:00 2001 From: ElinaPetersson Date: Fri, 27 Mar 2026 11:26:27 +0100 Subject: [PATCH 2/3] Added brain pipeline contribution to csv --- doc/code_contributions_record.csv | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/code_contributions_record.csv b/doc/code_contributions_record.csv index a347170..dd7753c 100644 --- a/doc/code_contributions_record.csv +++ b/doc/code_contributions_record.csv @@ -29,4 +29,5 @@ IVIM,Fitting,LSQ fitting,Part of the SUPER-IVIM-DC python package - trust region IVIM,Fitting,LSQ fitting,Part of the SUPER-IVIM-DC python package - segmented algorithm,TCML_TechnionIIT,TF2.4_IVIM-MRI_CodeCollection/src/original/TCML_TechnionIIT/SUPER-IVIM-DC,Noam Korngut/Elad Rotman/Onur Afacan Sila Kurugol/Yael Zaffrani-Reznikov/Shira Nemirovsky-Rotman/Simon Warfield/Moti Freiman,TCML Technion IIT,super_ivim_dc.source.Classsic_ivim_fit.IVIM_fit_sls,https://doi.org/10.1007/978-3-031-16434-7_71,TCML_TechnionIIT_lsqSLS IVIM,Fitting,LSQ fitting,Part of the SUPER-IVIM-DC python package - Levenberg Marquart lsq algorithm initialized with segmented fitting,TCML_TechnionIIT,TF2.4_IVIM-MRI_CodeCollection/src/original/TCML_TechnionIIT/SUPER-IVIM-DC,Noam Korngut/Elad Rotman/Onur Afacan Sila Kurugol/Yael Zaffrani-Reznikov/Shira Nemirovsky-Rotman/Simon Warfield/Moti Freiman,TCML Technion IIT,super_ivim_dc.source.Classsic_ivim_fit.IVIM_fit_sls_lm,https://doi.org/10.1007/978-3-031-16434-7_71,TCML_TechnionIIT_lsq_sls_lm IVIM,Fitting,LSQ fitting,Part of the SUPER-IVIM-DC python package - trust region lsq algorithm initialized with segmented fitting,TCML_TechnionIIT,TF2.4_IVIM-MRI_CodeCollection/src/original/TCML_TechnionIIT/SUPER-IVIM-DC,Noam Korngut/Elad Rotman/Onur Afacan Sila Kurugol/Yael Zaffrani-Reznikov/Shira Nemirovsky-Rotman/Simon Warfield/Moti Freiman,TCML Technion IIT,super_ivim_dc.source.Classsic_ivim_fit.IVIM_fit_sls_trf,https://doi.org/10.1007/978-3-031-16434-7_71,TCML_TechnionIIT_lsq_sls_trf -IVIM,Fitting,Segmented linear fitting,Consensus algorithm,TF_reference,TF2.4_IVIM-MRI_CodeCollection/src/original/TF_reference/,Ben Neijndorff/OSIPI taskforce 2.4,OSIPI,segmented_IVIMfit,tba,TF_reference_IVIMfit \ No newline at end of file +IVIM,Fitting,Segmented linear fitting,Consensus algorithm,TF_reference,TF2.4_IVIM-MRI_CodeCollection/src/original/TF_reference/,Ben Neijndorff/OSIPI taskforce 2.4,OSIPI,segmented_IVIMfit,tba,TF_reference_IVIMfit +IVIM,Preprocessing,Full pipeline,Brain pipeline,EP_GU,TF2.4_IVIM-MRI_CodeCollection/src/original/EP_GU,Elina Petersson,University of Gothenburg,brain_preproc,tba, \ No newline at end of file From 1d85015c0f0f3a0b2c1c5c86b0fbf852e5463244 Mon Sep 17 00:00:00 2001 From: ElinaPetersson Date: Fri, 27 Mar 2026 11:31:20 +0100 Subject: [PATCH 3/3] hide the degibs test --- tests/IVIMpreproc/unit_tests/test_degibbs.py | 82 +------------------- 1 file changed, 1 insertion(+), 81 deletions(-) diff --git a/tests/IVIMpreproc/unit_tests/test_degibbs.py b/tests/IVIMpreproc/unit_tests/test_degibbs.py index 656d36b..4287ca8 100644 --- a/tests/IVIMpreproc/unit_tests/test_degibbs.py +++ b/tests/IVIMpreproc/unit_tests/test_degibbs.py @@ -1,81 +1 @@ -''' -Not done! Need a better metric than just noise correlation - -''' -# %% -from phantoms.brain.sim_brain_phantom_preproc import simulate_brain_phantom - -simulate_brain_phantom(snr = 50) -#%% -import nibabel as nib -import numpy as np -from src.original.EP_GU.brain_pipeline import degibbs_wrap -import matplotlib.pyplot as plt -import os - -# load brain phantom -S_ref = nib.load('phantoms/brain/data/diffusive_reference_relax.nii.gz').get_fdata() - -# Convert to k-space -S_k = np.fft.fftn(S_ref,axes=(0,1)) -S_k = np.fft.fftshift(S_k,axes=(0,1)) - -plt.subplot(1,2,1) -plt.imshow(np.log(np.abs(S_k[:,:,30,0])+1),cmap='gray') -plt.xticks([]) -plt.yticks([]) - -# Crop k-space -S_k[:10,:,:,:] = 0 -S_k[-10:,:,:,:] = 0 -# S_k[:,:10,:,:] = 0 -# S_k[:,-10:,:,:] = 0 - -# Test plot -plt.subplot(1,2,2) -plt.imshow(np.log(np.abs(S_k[:,:,30,0])+1),cmap='gray') -plt.xticks([]) -plt.yticks([]) -plt.show() - -# Inverse Fourier transform -S_crop = np.fft.ifftshift(S_k,axes=(0,1)) -S_crop = np.fft.ifftn(S_crop,axes=(0,1)).real - -# Save image -S_crop_nii = nib.Nifti1Image(S_crop.astype(np.float32),np.eye(4)) -S_crop_file = 'phantoms/brain/data/diffusive_reference_relax_cropped.nii.gz' -nib.save(S_crop_nii,S_crop_file) - -# Apply degibbs -S_degibbs_file = degibbs_wrap(S_crop_file) - -# Plot results -S_degibbs = nib.load(S_degibbs_file).get_fdata() -plt.subplot(1,3,1) -plt.imshow(np.rot90(S_ref[:,:,30,0]),cmap='gray') -plt.xticks([]) -plt.yticks([]) -plt.subplot(1,3,2) -plt.imshow(np.rot90(S_crop[:,:,30,0]),cmap='gray') -plt.xticks([]) -plt.yticks([]) -plt.subplot(1,3,3) -plt.imshow(np.rot90(S_degibbs[:,:,30,0]),cmap='gray') -plt.xticks([]) -plt.yticks([]) -plt.show() - -mask = nib.load(os.path.join('phantoms','brain','data','diffusive_snr50_relax_mask.nii.gz')).get_fdata() - -def noise_correlation(img): - img = img - np.mean(img) - return np.sum(img[:, :-1] * img[:, 1:]) / np.sum(img**2) - -S_crop = nib.load(S_crop_file).get_fdata() -S_degibbs = nib.load(S_degibbs_file).get_fdata() -S_crop[mask==0,:]=0 -S_degibbs[mask==0,:]=0 - -print('Noise correlation before degibbs: {}'.format(noise_correlation(S_crop))) -print('Noise correlation after degibbs: {}'.format(noise_correlation(S_degibbs))) \ No newline at end of file +# \ No newline at end of file