利用Nibabel载入示例图片,并进行图像切片

nibabel是一个可以读取和处理.nii格式图像的python库

1.利用Nibabel载入示例图片

import os
import numpy as np
import nibabel as nib
#载入模块
from nibabel.testing import data_path
example_file = os.path.join(data_path, 'example4d.nii.gz')
#载入示例图片
img = nib.load(example_file)
img.shape
#output:(128, 96, 24, 2) #图片大小

2.运用Nibabel进行图像切片

问题描述:img为(128, 96, 24, 2)大小的4D图像,想要切片为3D图像(选取最后一维时间序列的某一个时间点)

import nibabel as nib
img1 = img.slicer[:,:,:,0]
img1.shape
#output:(128, 96, 24)

猜你喜欢

转载自blog.csdn.net/DoReAGON/article/details/84594592