Nibabel

2020-05-05  本文已影响0人  zelda2333

Nibabel 是 channel_last,即(240,240,155),其中155是图像通道数,也就是155张图像,可以把nii看成二维图像,也可以看成三维。

pip install nibabel
example_filename = os.path.join(data_path, 'example.nii.gz')
img = nib.load(example_filename)
img.shape
(512, 512, 75)

512x512矩阵中存储的是 CT值,单位为HU

数据包含三个主要的部分

如果你要对 CT图像进行 HU值的处理, 那么就一定要在使用nibabel 库之后立刻就进行操作,不要等使用 opencv 等工具后在进行操作。

使用 get_fdata , 就可以转为float 为 dtype 的 ndarray类型的 object

img = img.get_fdata()
img.affine.shape
(4, 4)
#写法1
img.to_filename(os.path.join('output', 'test.nii.gz')
#写法2
nib.save(img, os.path.join('output', 'test.nii.gz')
import matplotlib
matplotlib.use('TkAgg')
 
from matplotlib import pylab as plt
import nibabel as nib
from nibabel import nifti1
from nibabel.viewers import OrthoSlicer3D
 
example_filename = './Brats18_2013_2_1_flair.nii.gz'
 
img = nib.load(example_filename)
print (img)
print (img.header['db_name'])   # 输出头信息

# 由文件本身维度确定,可能是3维,也可能是4维 
width,height,queue=img.dataobj.shape
 
OrthoSlicer3D(img.dataobj).show()
 
num = 1
for i in range(0,queue,10):
 
    img_arr = img.dataobj[:,:,i]
    plt.subplot(5,4,num)
    plt.imshow(img_arr,cmap='gray')
    num +=1
 
plt.show()

https://blog.csdn.net/qq_37471316/article/details/86217476
https://blog.csdn.net/alxe_made/article/details/80512423

参考链接:
医学图像分析--雷锋网
NiBabel 手册
CT图像的处理--Pierce_KK
采用最大连通域算法对三维医学图像分割结果做后处
如何读取并对nii三维数据进行切片处理、转换格式保存
NIFTI(.nii)数据头文件解析

上一篇 下一篇

猜你喜欢

热点阅读