Пример #1
0
def __read_xml_by_slide__(xml_path,
                          slide_path,
                          slide_batch,
                          pro_method,
                          image_method,
                          zoom,
                          format_trans=None,
                          is_positive=True,
                          sub_class=None,
                          is_hard=False):
    # get slide format
    slide_format = slide_path[slide_path.rfind('.') + 1:]
    slide_proxy = srf.get_proxy(slide_format)

    # construct slide info
    try:
        slide_proxy.open(slide_path)
        seg = '\\'  # 默认路径分割符
        if slide_path.find(seg) == -1:
            seg = '/'
        slide_name = slide_path[slide_path.rfind(seg) + 1:]
        slide_path = slide_path[:slide_path.rfind(seg)]
        slide_path = slide_path.replace('/', '\\')
        mpp = slide_proxy.mpp()

        # modify person's name and last modify time
        m_name = 'csh'
        m_time = time.strftime('"%Y-%m-%d %I:%M:%S"',
                               time.localtime(os.stat(xml_path).st_ctime))
        modify_info = ModifyInfo(m_name, m_time)

        file_permission = None  # Tentatively None
        md5 = mmd5(xml_path)

        slide_info = SlideInfo(slide_path,
                               slide_name,
                               slide_batch,
                               pro_method,
                               image_method,
                               mpp,
                               zoom,
                               slide_format,
                               format_trans,
                               is_positive,
                               is_hard,
                               width=slide_proxy.width(),
                               height=slide_proxy.height(),
                               sub_class=sub_class,
                               bounds_x=slide_proxy.boundsx(),
                               bounds_y=slide_proxy.boundsy(),
                               modify_info=modify_info,
                               file_permission=file_permission,
                               md5_info=md5)
        slide_proxy.close()
    except:
        raise SlideError("slide read error!")

    annos, _ = __read_xml_by_path__(xml_path)
    return slide_info, annos
Пример #2
0
def get_slide_info(slide_path, slide_format):
    slide_path = slide_path.replace('\\', '/')
    slide_name = slide_path[slide_path.rfind('/') + 1:]
    slide_path = slide_path[:slide_path.rfind('/')]

    pro_method = 'Non-BD'
    image_method = slide_path.split('/')[2]
    slide_group = slide_path.split('/')[3]
    if slide_path.find('Not_BD') != -1:
        pro_method = 'Non-BD'

    zoom = '20x'
    is_positive = 'Yes'
    if slide_path.find('Neg') != -1 or slide_path.find('neg') != -1:
        is_positive = 'No'

    mpp, width, height, bounds_x, bounds_y = -1, -1, -1, -1, -1
    try:
        sr = srf.get_proxy(slide_format)
        sr.open(os.path.join(slide_path, slide_name))

        mpp = sr.mpp()
        if float(mpp) < 0.2:
            zoom = '40x'
        width = sr.width()
        height = sr.height()
        bounds_x = sr.boundsx()
        bounds_y = sr.boundsy()

        sr.close()
    except:
        read_slide_log.write(
            os.path.join(slide_path, slide_name) + '\t read exception\n')
        print(os.path.join(slide_path, slide_name), ' read exception')
        zoom = ''

    print(slide_path, '---', slide_name, ' ', mpp)
    slide = SlideInfo(slide_path, slide_name, slide_group, pro_method,
                      image_method, mpp, zoom, slide_format, 'NULL',
                      is_positive, '', width, height, '', bounds_x, bounds_y)
    # slide.show_info()
    return slide
Пример #3
0
xml_items = os.listdir(detect_path)

update_sql_flag = True
save_img_flag = True
# WNLO's Shengfuyou_3th and Shengfuyou_5th
for xml_item in xml_items:
    xmls = os.listdir(os.path.join(detect_path, xml_item))
    xmls = [x for x in xmls if x.find('.json') != -1]
    pro_method = 'BD'
    image_method = 'BD'
    slide_group = xml_item
    is_positive = '%'
    zoom = '20x'
    slide_format = 'srp'

    slide_read = srf.get_proxy(slide_format)
    for xk, xml in enumerate(xmls):
        name = xml[:xml.find('.json')]
        # handle detection xml
        c_xml_path = os.path.join(detect_path, xml_item, xml)
        json_annos = read_detection_json(c_xml_path)
        # generate anno by json

        print('(%d/%d)' % (xk + 1, len(xmls)), c_xml_path, len(json_annos))

        # query slide info
        slide_list = query_slide_info(pro_method, image_method, slide_group,
                                      is_positive, slide_format,
                                      name + '.' + slide_format, zoom)
        assert len(slide_list) == 1
        slide_info = slide_list[0]
Пример #4
0
      pro_method, image_method, slide_group;'

slide_batches = sql_proxy.execute_query(sql)

log = open(os.path.join(anno_imgs_path, 'log.txt'), 'w')
for slide_batch in slide_batches[2:4]:
    slides = query_slide_info(pro_method=slide_batch[0],
                              image_method=slide_batch[1],
                              slide_group=slide_batch[2],
                              is_positive=slide_batch[3],
                              zoom=slide_batch[4])
    print(slide_batch, len(slides))

    if len(slides) <= 0:
        continue
    slide_reader = srf.get_proxy(slides[0].slide_format())

    item = '%s__%s__%s__%s__%s' % (slide_batch[0], slide_batch[1],
                                   slide_batch[2], 'Pos' if slide_batch[3]
                                   == 'Yes' else 'Neg', slide_batch[4])
    log.write(item + '\t' + str(len(slides)) + '\n')
    cpath = os.path.join(anno_imgs_path, item)
    if not os.path.exists(cpath):
        os.makedirs(cpath)

    for slide in slides:
        annos = query_annos(slide.sid())
        if len(annos) <= 0:
            continue
        # slide_reader = srf.get_proxy(slide.slide_format())
        # slide_reader.open(os.path.join(slide.slide_path(), slide.slide_name()))
Пример #5
0
recheck_list = read_recheck()

xml_path = 'O:/TransSrp/SZSQ_originaldata/Model3Labelfiles/xml'
xml_items = os.listdir(xml_path)
print(xml_items)
for k, xml_item in enumerate(xml_items):
    xmls = os.listdir(os.path.join(xml_path, xml_item))
    xmls = [x for x in xmls if x.find('.xml') != -1]
    # print(xml_item)
    us = xml_item.split('_')

    im = 'SZSQ'
    sf = 'sdpc'
    zoom = '40x'
    slide_group = us[0] + '_' + us[1]
    slide_read = srf.get_proxy(sf)
    # set model3_top path
    model3_top50_path = 'H:/model3/reco_top50/' + slide_group
    model2_top20_path = 'L:/GXB/model2_recon/SZSQ_originaldata/Shengfuyou_8th/positive/all'
    
    for xk, xml in enumerate(xmls):
        # print('%d/%d' % (xk, len(xmls)), im, sf, zoom, slide_group, xml)
        annos, _ = read_xml_by_path(os.path.join(xml_path, xml_item, xml))
        print(xml_item, xml, len(annos))
        if xk > 3:
            break
        continue
        name = xml[: xml.find('.')]
        slide_list = query_slide_info('Non-BD', im, slide_group, 'Yes', sf, 
                                      name + '.' + sf, zoom)
        assert len(slide_list) == 1