简体   繁体   English

如何从 3D NIfti 体积中获取二维切片?

[英]How can I obtain 2D slices from a 3D NIfti volume?

I'm currently using the following code to convert DCM slices into NIfti images:我目前正在使用以下代码将 DCM 切片转换为 NIfti 图像:

import dicom2nifti
import os

dicom2nifti.convert_directory("input_path", "output_path", compression=True, reorient=True)

This code will generate a 3D NIfti volume.此代码将生成一个 3D NIfti 卷。

How can I obtain all the slices from this 3D NIfti volume?如何从这个 3D NIfti 卷中获取所有切片?

Use the package nibabel .使用 package nibabel A simple working example opens your NIfTI file as a numpy 3D matrix, which can use for your processing needs:一个简单的工作示例将您的 NIfTI 文件打开为 numpy 3D 矩阵,可用于您的处理需求:

import nibabel as nib
import numpy as np
import matplotlib.plot as plt


my_nifti = nib.load('YOURNIFTIFILE.nii').get_fdata()

# get the shape of your NIfTI
my_nifti.shape

# access it as 3D numpy array
nifti_slice = my_nifti[:,:,59]

# display the slice
plt.imshow(nifti_slice)
plt.show()

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

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