Python 使用 SimpleITK 读取和可视化 NIfTI 格式 CT 文件,并加载 Mask
import os import SimpleITK as sitk
定义文件夹路径
folder_path = 'path_to_folder'
获取文件夹下所有.nii.gz文件的路径
file_paths = [os.path.join(folder_path, file) for file in os.listdir(folder_path) if file.endswith('.nii.gz')]
遍历每个文件进行可视化
for file_path in file_paths: # 读取nifti文件 image = sitk.ReadImage(file_path)
# 可视化
sitk.Show(image)
# 加载mask
mask_path = file_path.replace('.nii.gz', '_mask.nii.gz')
if os.path.exists(mask_path):
mask = sitk.ReadImage(mask_path)
sitk.Show(mask)
原文地址: https://www.cveoy.top/t/topic/fzxU 著作权归作者所有。请勿转载和采集!