简体   繁体   中英

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.

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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM