コード例 #1
0
def get_id_list(slides_dir):
    id_list = []
    svs_file_list = filesystem.find_ext_files(slides_dir, "svs")
    id_list.extend([os.path.basename(ele) for ele in svs_file_list])
    SVS_file_list = filesystem.find_ext_files(slides_dir, "SVS")
    id_list.extend([os.path.basename(ele) for ele in SVS_file_list])
    id = [os.path.splitext(ele)[0] for ele in id_list]
    return id
コード例 #2
0
def get_slide_list(slides_dir):
    slide_list = []
    svs_file_list = filesystem.find_ext_files(slides_dir, "svs")
    slide_list.extend(svs_file_list)
    SVS_file_list = filesystem.find_ext_files(slides_dir, "SVS")
    slide_list.extend(SVS_file_list)

    return slide_list
コード例 #3
0
ファイル: utils.py プロジェクト: yedmed/LiverCancerSeg
def get_slide_filenames(slides_dir):
    slide_list = []
    svs_file_list = filesystem.find_ext_files(slides_dir, "svs")
    slide_list.extend([os.path.basename(ele) for ele in svs_file_list])
    SVS_file_list = filesystem.find_ext_files(slides_dir, "SVS")
    slide_list.extend([os.path.basename(ele) for ele in SVS_file_list])
    slide_filenames = [os.path.splitext(ele)[0] for ele in slide_list]

    slide_filenames.sort()

    return slide_filenames
コード例 #4
0
def locate_tissue(slides_dir):
    slide_list = []
    svs_file_list = filesystem.find_ext_files(slides_dir, "svs")
    slide_list.extend(svs_file_list)
    SVS_file_list = filesystem.find_ext_files(slides_dir, "SVS")
    slide_list.extend(SVS_file_list)

    tissue_dir = os.path.join(os.path.dirname(slides_dir), "Visualization/TissueLoc")
    filesystem.overwrite_dir(tissue_dir)
    for ind, slide_path in enumerate(slide_list):
        print("processing {}/{}".format(ind+1, len(slide_list)))
        # locate tissue contours with default parameters
        cnts, d_factor = tl.locate_tissue_cnts(slide_path, max_img_size=2048, smooth_sigma=13,
                                               thresh_val=0.88, min_tissue_size=120000)
        cnts = sorted(cnts, key=lambda x: cv2.contourArea(x), reverse=True)

        # if len(cnts) != 1:
        #     print("There are {} contours in {}".format(len(cnts), os.path.basename(slide_path)))

        # load slide
        select_level, select_factor = tl.select_slide_level(slide_path, max_size=2048)
        wsi_head = pyramid.load_wsi_head(slide_path)
        slide_img = wsi_head.read_region((0, 0), select_level, wsi_head.level_dimensions[select_level])
        slide_img = np.asarray(slide_img)[:,:,:3]
        slide_img = np.ascontiguousarray(slide_img, dtype=np.uint8)

        # change not valid poly to convex_hull
        cnt_arr = cv_cnt_to_np_arr(cnts[0])
        cnt_poly = np_arr_to_poly(cnt_arr)
        if cnt_poly.is_valid == True:
            valid_cnt = cnts[0].astype(int)
        else:
            valid_arr = poly_to_np_arr(cnt_poly.convex_hull)
            valid_cnt = np_arr_to_cv_cnt(valid_arr).astype(int)
        cv2.drawContours(slide_img, [valid_cnt], 0, (0, 255, 0), 8)

        # overlay and save
        # cv2.drawContours(slide_img, cnts, 0, (0, 255, 0), 8)
        tissue_save_name = os.path.splitext(os.path.basename(slide_path))[0] + ".png"
        tissue_save_path = os.path.join(tissue_dir, tissue_save_name)
        io.imsave(tissue_save_path, slide_img)
コード例 #5
0
def test_find_ext_files():
    input_dir = os.path.join(DATA_DIR, 'input')
    ext = '.png'

    filelist = find_ext_files(input_dir, ext)

    if len(filelist) == 0:
        print("No file with given extension")
    else:
        print("There are {} files end with {}".format(len(filelist), ext))
        for ind, cur_file in enumerate(filelist):
            print("{}: {}".format(ind + 1, cur_file))
コード例 #6
0
def predit_all_feas(model, args):
    slide_path = os.path.join(args.slide_dir, args.dset)
    slide_list = filesystem.find_ext_files(slide_path, "tiff")
    print("There are {} slides in totoal.".format(len(slide_list)))
    slide_list.sort()

    fea_dir = os.path.join(args.fea_dir, args.model_type, args.dset)

    print("Start processing...")
    print("="*80)
    slide_start = time.time()
    for ind, slide_path in enumerate(slide_list):
        slide_filename = os.path.splitext(os.path.basename(slide_path))[0]
        slide_head = openslide.OpenSlide(slide_path)
        print("Processing {}, width: {}, height: {}, {}/{}".format(
            slide_filename, slide_head.dimensions[0], slide_head.dimensions[1], ind+1, len(slide_list)))
        predict_slide_fea(slide_path, model, fea_dir, args)
    print("="*80)
    slide_elapsed = time.time() - slide_start
    print("Time cost: " + time.strftime("%H:%M:%S", time.gmtime(slide_elapsed)))
    print("Finish Prediction...")
コード例 #7
0
# -*- coding: utf-8 -*-

import os, sys
from pydaily import filesystem
from skimage.external.tifffile import imsave

sys.path.insert(0, '.')
from kfb_io.io_image import patch_read_slide

if __name__ == "__main__":
	input_root = str(sys.argv[1])   # kfb folder
	save_root = str(sys.argv[2])    # tif folder

    if not os.path.exists(save_root):
        os.makedirs(save_root)
    kfb_files = filesystem.find_ext_files(input_root, "kfb")

	for ind, this_kfb_path in enumerate(kfb_files):
        print("Processing {}/{}".format(ind+1, len(kfb_files)))
	    img_name = os.path.basename(this_kfb_path)
	    img_name_noext = os.path.splitext(img_name)[0]

	    this_raw_data = patch_read_slide(this_kfb_path, level=1)
	    save_path = os.path.join(save_root, img_name_noext+'.tif')
	    imsave(save_path, this_raw_data, compress=9, bigtiff=True)
コード例 #8
0
# -*- coding: utf-8 -*-

import os, sys
import deepdish as dd
import argparse
from pydaily import filesystem


def set_args():
    parser = argparse.ArgumentParser(description="check fea generation")
    parser.add_argument('--fea_dir',
                        type=str,
                        default="../data/CV04/Feas/vgg16bn")
    parser.add_argument('--dset', type=str, default="train")

    args = parser.parse_args()
    return args


if __name__ == "__main__":
    args = set_args()
    feas_dir = os.path.join(args.fea_dir, args.dset)
    h5_list = filesystem.find_ext_files(feas_dir, ".h5")
    for ele in h5_list:
        cur_fea_dict = dd.io.load(ele)
        num_patch = len(cur_fea_dict['probs'])
        if num_patch <= 128:
            print("Regions in {} is {}".format(ele, num_patch))