直接在Pycharm中CV 安装相应的包可对具体内容取消注释进行展示
import numpy as np
import nibabel as nib
import matplotlib.pyplot as plt
from nibabel.viewers import OrthoSlicer3D
import matplotlib
matplotlib.use('TkAgg')
image_path = r"G:\Task66_K\imagesTr\9006723.nii.gz"
image_obj = nib.load(image_path)
print(f'文件路径: {image_path}')
print(f'图像类型: {type(image_obj)}')
image_data = image_obj.get_fdata()
depth, height, width = image_data.shape
print(f"The image object height: {height}, width:{width}, depth:{depth}")
print(f'image value range: [{image_data.min()}, {image_data.max()}]')
OrthoSlicer3D(image_obj.dataobj).show()
print(image_obj.header.keys())
pixdim = image_obj.header['pixdim']
print(f'z轴分辨率: {pixdim[3]}')
print(f'in plane 分辨率: {pixdim[1]} * {pixdim[2]}')
z_range = pixdim[3] * depth
x_range = pixdim[1] * height
y_range = pixdim[2] * width
print(f'扫描范围:', x_range, y_range, z_range)
maxval = 140
i = np.random.randint(0, maxval)
print(f"Plotting z Layer {i} of Image")
plt.imshow(image_data[:, :, i], cmap='gray')
plt.axis('off');
plt.show()
label_path = "G:\Task66_K\labelsTr\9006723.nii.gz"
label_obj = nib.load(label_path)
label_array = label_obj.get_fdata()
print(f'label_path: {label_path}')
print(f'标签中有几种值: {np.unique(label_array)}')
print(f'每个标签像素数量:',np.unique(label_array, return_counts=True))
参考内容:
https://blog.csdn.net/u014264373/article/details/119545255?spm=1001.2101.3001.6650.12&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-13.highlightwordscore&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-13.highlightwordscore
|