Example #1
0
def visualise_cut(slide,
                  list_pos,
                  res_to_view=None,
                  color='red',
                  size=12,
                  title=""):
    map_col = {0: "white", 1: "red", 2: "green", 3: "blue"}
    if res_to_view is None:
        res_to_view = slide.level_count - 3
    whole_slide = np.array(
        slide.read_region((0, 0), res_to_view,
                          slide.level_dimensions[res_to_view]))
    max_x, max_y = slide.level_dimensions[res_to_view]
    fig = plt.figure(figsize=(size, size))
    ax = fig.add_subplot(111, aspect='equal')
    # ax.imshow(flip_vertical(whole_slide))  # , origin='lower')
    # whole_slide = flip_horizontal(whole_slide)
    ax.imshow(whole_slide)
    for para in list_pos:
        top_left_x, top_left_y = UOS.get_X_Y_from_0(slide, para[0], para[1],
                                                    res_to_view)
        w, h = UOS.get_size(slide, para[2], para[3], para[4], res_to_view)
        p = patches.Rectangle((top_left_x, max_y - top_left_y - h),
                              w,
                              h,
                              fill=False,
                              edgecolor=map_col[para[5]])
        p = patches.Rectangle((top_left_x, top_left_y),
                              w,
                              h,
                              fill=False,
                              edgecolor=map_col[para[5]])
        ax.add_patch(p)
    ax.set_title(title, size=20)
    return fig
Example #2
0
    whole_img = np.array(whole_img)[:, :, 0:3]

    small_img = resize(whole_img, (500, 500))
    small_img = img_as_ubyte(small_img)
    mask = ROI_binary_mask(small_img, ticket=(80, 80, 80))
    mask = mask.astype('uint8')
    mask[mask > 0] = 255
    mask_tissue = resize(mask, last_dim_inv, order=0)
    mask_tissue = img_as_ubyte(mask_tissue)
    mask_tissue[mask_tissue > 0] = 255

    class_0 = np.zeros_like(whole_img[:, :, 0], dtype=float)
    class_1 = np.zeros_like(whole_img[:, :, 0], dtype=float)
    class_2 = np.zeros_like(whole_img[:, :, 0], dtype=float)
    class_3 = np.zeros_like(whole_img[:, :, 0], dtype=float)
    s_0_x, s_0_y = UOS.get_size(WSI, 2 * 448, 2 * 448, 0, last_dim_n)
    model = load_model(WEIGHTS)

    for x in range(0, whole_img.shape[0], s_0_x):
        for y in range(0, whole_img.shape[1], s_0_y):
            if mask_tissue[x, y] != 0:
                x_0, y_0 = UOS.get_X_Y(WSI, y, x, last_dim_n)
                img = resize(
                    np.array(WSI.read_region((x_0, y_0), 0,
                                             (448 * 2, 448 * 2)))[:, :, 0:3],
                    (224, 224))
                img = img_as_ubyte(img).astype(float) - mean
                img = np.expand_dims(img, axis=0)
                res = model.predict(img)
                class_0[x:(x + s_0_x), y:(y + s_0_y)] = res[0][0]
                class_1[x:(x + s_0_x), y:(y + s_0_y)] = res[0][1]
Example #3
0
mask[mask > 0] = 255
mask_tissue = resize(mask, last_dim_inv, order=0)
mask_tissue = img_as_ubyte(mask_tissue)
mask_tissue[mask_tissue > 0] = 255

GT_file = imread(GT_path)
GT_file[GT_file > 0] = 255
Red_area = GT_file[:, :, 0]
Red_area = img_as_ubyte(resize(Red_area, last_dim_inv, order=0))
Green_area = GT_file[:, :, 1]
Green_area = img_as_ubyte(resize(Green_area, last_dim_inv, order=0))
Blue_area = GT_file[:, :, 2]
Blue_area = img_as_ubyte(resize(Blue_area, last_dim_inv, order=0))

mask_tissue = mask_tissue - Red_area - Green_area - Blue_area
s_0_x, s_0_y = UOS.get_size(scan, 448, 448, 0, last_dim_n)

channels = (mask_tissue, Red_area, Green_area, Blue_area)

list_channel = []
for k, c in enumerate(channels):
    i = 0
    c_cop = c.copy()
    while ((c_cop > 0).sum() > 0 and i < number_of_imgs):
        x_l, y_l = np.where(c > 0)
        pic = random.randint(0, len(x_l)) - 1
        x = x_l[pic] - s_0_x // 2
        y = y_l[pic] - s_0_y // 2
        c_cop[(x - s_0_x):(x + s_0_x), (y - s_0_y):(y + s_0_y)] = 0
        x_0, y_0 = UOS.get_X_Y(scan, x, y, last_dim_n)
        # add cube to final list: label, x,y for read_imd

        small_img = resize(whole_img, (500, 500))
        small_img = img_as_ubyte(small_img)
        mask = ROI_binary_mask(small_img, ticket=(80,80,80))
        mask = mask.astype('uint8')
        mask[mask > 0] = 255
        mask_tissue = resize(mask, last_dim_inv, order=0)
        mask_tissue = img_as_ubyte(mask_tissue)
        mask_tissue[mask_tissue > 0] = 255

        class_0 = np.zeros_like(whole_img[:,:,0])
        class_1 = np.zeros_like(whole_img[:,:,0])
        class_2 = np.zeros_like(whole_img[:,:,0])
        class_3 = np.zeros_like(whole_img[:,:,0])
        s_0_x, s_0_y = UOS.get_size(WSI, 224, 224, 0, last_dim_n)

        model = load_model(WEIGHTS)

        for x in range(0, whole_img.shape[0], s_0_x):
            for y in range(0, whole_img.shape[1], s_0_y):
                if mask_tissue[x, y] != 0: 
                    img = WSI.read_region((x-s_0_x/2, y-s_0_y/2), 0, (224, 224))
                    img = img.astype(float) - mean
                    img = np.expand_dims(img, axis=0)
                    res = model.predict(img)
                    class_0[x, y] = res[0]
                    class_1[x, y] = res[1]
                    class_2[x, y] = res[2]
                    class_3[x, y] = res[3]