dicom序列转nii格式

import dicom2nifti # pip install dicom2nifti
import os


def find_workdir(mainDir):
    """ 返回所有的目录 """
    all_work_dirs = []
    subdirs = os.listdir(mainDir)
    for subdir in subdirs:
        if subdir == "readme.md" or int(subdir) < 244:
            continue
        part_dir = os.path.join(mainDir,subdir) # D:/lung_blood/244
        filesAnddir =  os.listdir(part_dir)
        for item in filesAnddir:
            if os.path.isdir(os.path.join(part_dir,item)):
                part_dir = os.path.join(part_dir,item)  # D:/lung_blood/243/HKMTEVPH
                serizes_dir_version  =  os.listdir(part_dir)
                for serize in serizes_dir_version:
                    if os.path.isdir(os.path.join(part_dir,serize)):
                        work_dir = os.path.join(part_dir,serize)
                        all_work_dirs.append(work_dir)
    
    return all_work_dirs




if __name__ == '__main__':
    Main_Dir = "D:/lung_blood_delInfo"
    all_workDirs = find_workdir(Main_Dir)
    for workdir in all_workDirs:
        print(f'{workdir} converting begin...')
        # 转换后的nii文件就存在该workdir下
        # ------------------------------------------------
        # 主要就是这一句代码,把dicom序列所在的文件夹传进去就可以了
        # -----------------------------------------------
        dicom2nifti.convert_directory(workdir,workdir)

        print(f'{workdir} converting complete!')

你可能感兴趣的:(dcm处理,医学图像处理,python)