• 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)

  • 相关阅读:
    CHATGPT中国免费网页版有哪些-CHATGPT中文版网页
    Bond配置文件配置
    HTML5离线储存
    从零开始学React--JSX
    Aws配置钉钉告警实现
    虚拟机的网络模式
    密码学入门
    JavaScript -- 多种类型转换方法总结
    C++的爬山算法
    Java入门第二季
  • 原文地址:https://blog.csdn.net/weixin_41275726/article/details/128067960