Search code examples
pythonpython-imaging-librarymedicalpydicommedical-imaging

How can I obtain axial slices of a 3D medical image saved as numpy array in python?


I have 3D volume medical image of size [284,143,143]. I want to extract axial slices from them and save them separatley in a folder. Can anyone tell me how can I acheive this in python.


Solution

  • I'm not sure if this is what you're look for but you can always use numpy and slice while indexing. (I'm assuming your image is a PIL image because of the tag)

    import numpy as np
    from PIL import Image
    
    ...`
    
    arr = np.array(PIL_Image)
    for i in range(284):
        slice = Image.fromarray(arr[i, :, :])
        slice.save(f"slice{i}.jpg")