简体   繁体   English

如何在 python 中获取保存为 numpy 数组的 3D 医学图像的轴向切片?

[英]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].我有尺寸为 [284,143,143] 的 3D 体积医学图像。 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.谁能告诉我如何在 python 中实现这一点。

I'm not sure if this is what you're look for but you can always use numpy and slice while indexing.我不确定这是否是您要查找的内容,但您始终可以在索引时使用 numpy 和切片。 (I'm assuming your image is a PIL image because of the tag) (由于标签,我假设您的图像是 PIL 图像)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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