LIDC数据集由xml提取小结节和非结节

注:小结节是指只有一个坐标的结节,它与其他结节的区别是没有characteristics。

from xml.dom.minidom import parse

# 解析xml
def parseXML(xml_path):
    nodules_coor = []
    non_nodules_coor = []

    domTree = parse(xml_path)
    # print(domTree)  # <xml.dom.minidom.Document object at 0x0000000003FD4E88>
    # print(type(domTree))  # <class 'xml.dom.minidom.Document'>
    # 文档根元素
    rootNode = domTree.documentElement
    print(rootNode.nodeName)  # LidcReadMessage
    exit(0)
    # 所有医生标注
    readingSessions = rootNode.getElementsByTagName("readingSession")
    # print(readingSessions)

    for rS in readingSessions:
        nodules = rS.getElementsByTagName("unblindedReadNodule")
        non_nodules = rS.getElementsByTagName("nonNodule")
        # 解析结节
        for nodule in nodules:
            if nodule.getElementsByTagName("characteristics"):
                continue
            roi = nodule.getElementsByTagName("roi")[0]
            Z_w = roi.getElementsByTagName("imageZposition")[0].childNodes[0].data
            # print("Z_w---", Z_w)
            edgemap = roi.getElementsByTagName("edgeMap")[0]
            X_v = edgemap.getElementsByTagName("xCoord")[0].childNodes[0].data
            Y_v = edgemap.getElementsByTagName("yCoord")[0].childNodes[0].data
            coor = (int(X_v), int(Y_v), float(Z_w))
            if coor not in nodules_coor:
                nodules_coor.append(coor)

        # 解析非结节
        for non_nodule in non_nodules:
            Z_w = non_nodule.getElementsByTagName("imageZposition")[0].childNodes[0].data
            locus = non_nodule.getElementsByTagName("locus")[0]
            X_v = locus.getElementsByTagName("xCoord")[0].childNodes[0].data
            Y_v = locus.getElementsByTagName("yCoord")[0].childNodes[0].data
            coor = (int(X_v), int(Y_v), float(Z_w))
            if coor not in non_nodules_coor:
                non_nodules_coor.append(coor)
    print(r"Finish ", xml_path)
    return nodules_coor, non_nodules_coor


if __name__ == '__main__':
    xml_path = '115.xml'
    nodules_coor, non_nodules_coor = parseXML(xml_path)
    print("nodules_coor:", nodules_coor)
    print("len(nodules_coor):", len(nodules_coor))
    print("non_nodules_coor:", non_nodules_coor)
    print("len(non_nodules_coor):", len(non_nodules_coor))
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值