signed

QiShunwang

“诚信为本、客户至上”

【5】nibabel三维显示

2021/5/14 21:12:56   来源:

【1】参考代码

#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   test8.py
@Time    :   2021/04/30 16:53:05
@Author  :   Jian Song 
@Contact :   1248975661@qq.com
@Desc    :   None
'''

# here put the import lib

import matplotlib
matplotlib.use('TkAgg') 
from matplotlib import pylab as plt
import nibabel as nib
from nibabel import nifti1
from nibabel.viewers import OrthoSlicer3D

'''
nibabel三维显示
https://blog.csdn.net/qq_33254870/article/details/100125788
''' 
example_filename = 'F:\\mediacldata\\Pancreasimages\\Pancreas-CT\\data\\PANCREAS_0001.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()

【2】结果展示