Skip to content

Instantly share code, notes, and snippets.

@upupming
Created April 18, 2022 13:10
Show Gist options
  • Select an option

  • Save upupming/bca50c875a1badf238f3aa0c9c5b56f4 to your computer and use it in GitHub Desktop.

Select an option

Save upupming/bca50c875a1badf238f3aa0c9c5b56f4 to your computer and use it in GitHub Desktop.

Revisions

  1. upupming created this gist Apr 18, 2022.
    26 changes: 26 additions & 0 deletions sitk_sample_image.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    # References: https://simpleitk.readthedocs.io/en/master/link_AdvancedImageReading_docs.html

    import SimpleITK as sitk
    import time

    img_path = 'D:/DATA/CLD0318/patient_67.nii'

    a = time.time()
    X = sitk.ReadImage(img_path)
    b = time.time()
    print(f'sitk.ReadImage time: {b-a}')

    file_reader = sitk.ImageFileReader()
    file_reader.SetFileName(img_path)
    # file_reader.ReadImageInformation()
    # image_size = file_reader.GetSize()

    file_reader.SetExtractIndex([0, 0, 0])
    file_reader.SetExtractSize([128, 128, 128])
    img_1 = file_reader.Execute()

    c = time.time()
    print(f'Only read image region takes time: {c-b}')

    # sitk.ReadImage time: 5.593693733215332
    # Only read image region takes time: 0.06897830963134766