<jupyter_start><jupyter_text>Load and Save benchmark of nibabel and SimpleITK* load : nib > sitk* save : sitk > nib<jupyter_code>%%capture
!pip install SimpleITK nibabel
import numpy as np
import nibabel as nib
import SimpleITK as sitk
%%timeit
img = nib.load('/content/104_mask_Gallbladder_rot.nii')
img_affine  = img.affine
img = img.get_fdata(dtype=np.float32)
# img = np.asanyarray(img.dataobj)
# print(type(img))  # <class 'numpy.memmap'>
%%timeit
img2 = sitk.ReadImage('/content/104_mask_Gallbladder_rot.nii', sitk.sitkUInt8)
img2 = sitk.GetArrayFromImage(img2)
# print(type(img))    # <class 'numpy.memmap'>
%%timeit
d = nib.Nifti1Image(img,img_affine)
d.to_filename('xxxxx.nii.gz')
%%timeit
out = sitk.GetImageFromArray(img2)
sitk.WriteImage(out,'xxxxx.nii.gz')<jupyter_output>1 loop, best of 5: 316 ms per loop
{'fraction_non_alphanumeric': 0.13553113553113552, 'fraction_numerical': 0.0231990231990232, 'mean_word_length': 6.192982456140351, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '330580', 'license': 'MIT', 'n_tokens_mistral': 354, 'n_tokens_neox': 329, 'n_words': 67, 'path': 'nib_sitk_benchmark.ipynb', 'repo_name': 'hihunjin/Code-snippet-for-everything', 'size': '819'}