Exemplo n.º 1
0
def get_mining_data_mask(path, maskdir):
    tumor_wsi_paths, _ = ops.get_tumor_wsi_path(path)
    for slide_path in tumor_wsi_paths:
        print('mining data from %s' % slide_path)
        tumor_mask_name, tumor_mask_exist = ops.name_and_exist(slide_path, maskdir, '_tumor_mask.png')
        tumor_tissue_mask_name, tissue_mask_exist = ops.name_and_exist(slide_path, maskdir, '_tissue_mask.png')

        tumor_mask = cv2.imread(os.path.join(maskdir, tumor_mask_name), 0)
        tissue_mask = cv2.imread(os.path.join(maskdir, tumor_tissue_mask_name), 0)

        kernel = cv2.getStructuringElement(shape=cv2.MORPH_RECT, ksize=(50, 50))
        dilate_tumor_mask = cv2.dilate(tumor_mask, kernel)

        dilate_tumor_mask_inv = cv2.bitwise_not(dilate_tumor_mask)
        tumor_mask_inv = cv2.bitwise_not(tumor_mask)

        mining_normal_mask_name, mining_normal_mask_exist = ops.name_and_exist(slide_path, maskdir, '_mining_few_normal_mask.png')
        if mining_normal_mask_exist == False:
            mining_Tumor_normal_mask = cv2.bitwise_and(dilate_tumor_mask_inv, tissue_mask)
            cv2.imwrite(os.path.join(maskdir, mining_normal_mask_name), mining_Tumor_normal_mask)

        mining_most_normal_mask_name, mining_most_normal_mask_exist = ops.name_and_exist(slide_path, maskdir,'_mining_most_normal_mask.png')
        if mining_most_normal_mask_exist == False:
            mining_most_normal_mask = cv2.bitwise_and(tumor_mask_inv, dilate_tumor_mask)
            cv2.imwrite(os.path.join(maskdir, mining_most_normal_mask_name), mining_most_normal_mask)
Exemplo n.º 2
0
def get_tumor_mask(path, level, maskdir):
    tumor_wsi_paths, tumor_xml_paths = ops.get_tumor_wsi_path(path)
    for tumor_wsi_path, tumor_xml_path in zip(tumor_wsi_paths, tumor_xml_paths):
        print('Get mask from: %s - %s' % (tumor_wsi_path, tumor_xml_path))
        tumor_slide = openslide.OpenSlide(tumor_wsi_path)

        tumor_slide_map = np.array(tumor_slide.get_thumbnail(tumor_slide.level_dimensions[level]))
        level_downsample = tumor_slide.level_downsamples[level]
        coors_list = ops.read_xml(tumor_xml_path, level_downsample)

        # draw boundary of tumor in map
        tumor_map_name, tumor_map_exist = ops.name_and_exist(tumor_wsi_path, maskdir, '_map.png')
        if tumor_map_exist == False:
            for coors in coors_list:
                cv2.drawContours(tumor_slide_map, np.array([coors]), -1, 255, 1)
            cv2.imwrite(os.path.join(maskdir, tumor_map_name), tumor_slide_map)

        # check tumor mask / draw tumor mask
        tumor_mask_name, tumor_mask_exist = ops.name_and_exist(tumor_wsi_path, maskdir, '_tumor_mask.png')
        if tumor_mask_exist == False:
            tumor_mask = np.zeros(tumor_slide.level_dimensions[level][::-1])
            for coors in coors_list:
                cv2.drawContours(tumor_mask, np.array([coors]), -1, 255, -1)
                cv2.imwrite(os.path.join(maskdir, tumor_mask_name), tumor_mask)

        # check tissue mask / draw tissue mask
        tumor_tissue_mask_name, tissue_mask_exist = ops.name_and_exist(tumor_wsi_path, maskdir, '_tissue_mask.png')
        if tissue_mask_exist == False:
            ops.saved_tissue_mask(tumor_slide, maskdir, tumor_tissue_mask_name, level)

        # check tumor_normal mask / draw normal mask
        normal_mask_name, normal_mask_exist = ops.name_and_exist(tumor_wsi_path, maskdir, '_normal_mask.png')
        if normal_mask_exist == False:
            ops.saved_normal_tumor_mask(maskdir, tumor_tissue_mask_name, tumor_mask_name, normal_mask_name)
Exemplo n.º 3
0
def get_normal_patches_from_most_normal_mask(path, level, maskdir):                                    #
    tumor_slide_paths, _ = ops.get_tumor_wsi_path(path)                                                #
    for slide_path in tumor_slide_paths:                                                               #
        ops.extract_patches_from_slide_and_mask(slide_path, maskdir, '_mining_most_normal_mask.png',   #
                                                level, is_for_tumor_patch=True, tumor_patch=False)     #
Exemplo n.º 4
0
def get_tumor_patches_from_tumor_slide(path, level, maskdir):
    tumor_slide_paths, _ = ops.get_tumor_wsi_path(path)
    for slide_path in tumor_slide_paths:
        # extract patches from slide
        ops.extract_patches_from_slide_and_mask(slide_path, maskdir, '_tumor_mask.png',
                                                level, is_for_tumor_patch=True, tumor_patch=True)
Exemplo n.º 5
0
def get_normal_patches_from_tumor_slide(path, level, maskdir):
    tumor_slide_paths, _ = ops.get_tumor_wsi_path(path)
    for slide_path in tumor_slide_paths:
        ops.extract_patches_from_slide_and_mask(slide_path, maskdir, '_normal_mask.png',
                                                level, is_for_tumor_patch=False, tumor_patch=False)