• raw文件检索规则


     文件夹|

                    医院|

                            病人|

                                    序列

                    医院|

                           病人|

                                    序列

    1. import os;import sys;import glob;
    2. # 默认同级目录
    3. strFileRoot = r"D:\VisualStudioCode\PyTorchDemo\medical_handle\test"
    4. strFileName = "filenames.txt" # 设置医院
    5. samples = []
    6. with open(os.path.join(strFileRoot, strFileName)) as f:
    7. # **设置检索指定医院**
    8. hospital_paths = [os.path.join(strFileRoot, hospital_line) for hospital_line in f.read().splitlines()]
    9. # 自动检索每个医院下的病人
    10. patient_paths = [glob.glob(os.path.join(hospital_path, "*")) for hospital_path in hospital_paths]
    11. # 自动检索每个病人的序列
    12. for patient_path in patient_paths:
    13. for patient in patient_path:
    14. # **设置检索指定序列**
    15. def get_series(patient, raw_name):
    16. path = os.path.join(patient, raw_name)
    17. return path if os.path.exists(path) else None
    18. patient_T1Imagefile = get_series(patient, "T1_reg_Axial.mhd")
    19. patient_T1CEImagefile = get_series(patient, "T1CE_reg_Axial.mhd")
    20. patient_Maskfile = get_series(patient, "T1_Segment_dilate.mhd")
    21. if patient_T1Imagefile and patient_Maskfile and patient_T1CEImagefile:
    22. samples.append(",".join([patient_T1Imagefile,patient_Maskfile,patient_T1CEImagefile]))
    23. samples.append(",".join([patient_T1CEImagefile,patient_Maskfile,patient_T1Imagefile]))
    24. if patient_T1Imagefile and patient_Maskfile and not patient_T1CEImagefile:
    25. samples.append(",".join([patient_T1Imagefile,patient_Maskfile,patient_T1Imagefile]))
    26. if not patient_T1Imagefile and patient_Maskfile and patient_T1CEImagefile:
    27. samples.append(",".join([patient_T1CEImagefile,patient_Maskfile,patient_T1CEImagefile]))
    28. ...
    29. ...
    30. ...
    31. len(samples)

  • 相关阅读:
    Linux 文件和目录列表(ls 命令)
    腾讯云标准型S5服务器和s6有什么区别?性能哪个强?
    html+css+javascript+jquery+bootstarp响应式旅行社旅游平台网站模板(14页)
    定制自己的 AI 角色CustomChar;AI知识点和面试题;提高llama 3 的微调速度Unsloth
    球的状态判定技巧
    【Vue】环境搭建
    关于VSCODE的插件 一
    软件测试肖sir__python之sys模块
    Kafka (二) ---------- Kafka 快速入门
    FreeRTOS教程3 中断管理
  • 原文地址:https://blog.csdn.net/weixin_41275726/article/details/128067960