Esempio n. 1
0
def get_gt_mask_temp(image_filename, args):
    mask_final_path = os.path.join(args.data_path, 'occ_mask_final', image_filename)
    gt_path_abs = get_gt_path(image_filename, args.dataset)

    gt_depth = cv_io.read(gt_path_abs)[192:192+128,192:192+160]
    final_soft = cv_io.read(mask_final_path).astype(np.float32) / 255.
    if len(final_soft.shape) > 2: final_soft = final_soft[...,0]
    final = np.zeros_like(final_soft)
    final[final_soft>0.5] = 1.0
    final[gt_depth<0.1] = 0.5

    gt_mask_path = os.path.join('tmp', 'gt_mask_'+image_filename).replace('.dpt', '.png')
    cv_io.save(gt_mask_path, (final*255).astype(np.uint8))

    return gt_mask_path
Esempio n. 2
0
def get_dif_map(est_path, gt_path, tol=0.2):
    est = cv_io.read(est_path)
    gt = cv_io.read(gt_path)
    m = np.min(gt)
    M = np.max(gt)
    gt_nromal = (gt - m) / (M - m) * 255 
    R = gt_nromal.copy()
    G = gt_nromal.copy()
    B = gt_nromal.copy()
    R [np.abs(est-gt)>tol] = 255
    G [np.abs(est-gt)>tol] = 0
    B [np.abs(est-gt)>tol] = 0
    R [gt < 1e-3] = 0
    G [gt < 1e-3] = 0
    B [gt < 1e-3] = 0
    error = np.stack([R,G,B],-1)
    cv_io.save('tmp/x.png', error.astype(np.uint8))
    return 'tmp/x.png'
Esempio n. 3
0
def score(image_filename, metric, args):
    mask_final_path = os.path.join(args.data_path, 'occ_mask_final', image_filename)
    mask_gt_path = os.path.join(args.data_path, 'occ_mask_gt', image_filename)

    gt_path = get_gt_path(image_filename, args.dataset)
    gt_depth = cv_io.read(gt_path)[192:192+128,192:192+160]
    
    final_soft = cv_io.read(mask_final_path).astype(np.float32) / 255.
    if len(final_soft.shape) > 2: final_soft = final_soft[...,0]
    final = np.zeros_like(final_soft)
    final[final_soft>0.5] = 1.0

    gt = cv_io.read(mask_gt_path).astype(np.float32) / 255.
    if len(gt.shape) > 2: gt = gt[...,0]

    final = final[gt_depth>0.1]
    gt = gt[gt_depth>0.1]
    final_DR = np.sum(final!=gt) / np.prod(gt.shape)

    return final_DR
Esempio n. 4
0
def ROI_box(rgb_file, args, thickness=3):
    rgb = cv_io.read(rgb_file)
    th = thickness
    x = 192; y = 192
    rgb[x-th:x+th,y-th:y+160+th,:] = [0,255,0]
    rgb[x+128-th:x+128+th,y-th:y+160+th,:] = [0,255,0]
    rgb[x-th:x+128+th,y-th:y+th,:] = [0,255,0]
    rgb[x-th:x+128+th,y+160-th:y+160+th,:] = [0,255,0]
    temp_save = os.path.join ('tmp', 'rgb_'+rgb_file.split(os.sep)[-1])
    cv_io.save(temp_save, rgb)
    return temp_save
Esempio n. 5
0
def get_gt_temp(image, args, inverse=True):
    gt_path_abs = get_gt_path(image, args.dataset)
    gt = cv_io.read(gt_path_abs)
    gt_norm = 1 / gt if inverse else gt.copy()
    gt_norm[gt<1e-3] = 0
    m = np.min(gt_norm)
    M = np.max(gt_norm)
    gt_norm = (gt_norm - m) / (M - m) * 255
    # gt_norm[gt<1e-3] = 255 / 2
    gt_path = os.path.join('tmp', 'gt_'+image).replace('.dpt', '.png')
    cv_io.save(gt_path, gt_norm.astype(np.uint8))
    return gt_path
Esempio n. 6
0
def ROI_box(gt, image, h, w, M, thickness=3):
    rgb = cv_io.read(image)
    rgb = draw_box(rgb, h, w)
    mask = np.zeros_like(gt)
    mask[gt < M] = 0
    mask[gt > M] = 255
    mask[gt < 0.01] = 255 // 2
    mask_color = mask[:, :, np.newaxis]
    mask_color = np.concatenate(
        (mask_color, np.zeros_like(mask_color), np.zeros_like(mask_color)),
        axis=2)
    mask_color = 0.8 * rgb + 0.2 * mask_color
    temp_save = os.path.join('examples/tmp',
                             'mask_ROI_' + image.replace(os.sep, '_')).replace(
                                 '.dpt', '.png')
    cv_io.save(temp_save, mask_color.astype(np.uint8))
    return temp_save
Esempio n. 7
0
def get_planes(gt, image, args, examples=4):
    gap_points = []
    th = 250
    while len(gap_points) < 8:
        gap_points = plane_finder.get_points(gt * 1000,
                                             None,
                                             args.n,
                                             args.k,
                                             th=th,
                                             f=args.f)
        th = th / 2
    line_normals, Ms, selected_points = plane_finder.find_lines(
        gap_points,
        number_of_lines=args.number_of_planes,
        method='ransac',
        plane_th=50,
        s=2)
    img = cv_io.read(image)

    mask_paths = list()
    masks = list()

    for i in range(examples):
        line_normal = line_normals[i]
        M = Ms[i]
        N = np.asarray([0, line_normal[2], -line_normal[1]])
        if np.linalg.norm(N) == 0:
            N = np.asarray([0, 0, -1])
        else:
            N = N / np.linalg.norm(N)

        N = np.reshape(N, [1, 1, 3])
        M = np.reshape(M, [1, 1, 3])
        offset = np.sum(-M * N)
        N = N / np.linalg.norm(N) * np.sign(-offset)
        offset *= np.sign(-offset)

        x = np.linspace(0, 1, gt.shape[0])
        y = np.linspace(0, 1, gt.shape[1])
        xv, yv = np.meshgrid(x, y, indexing='ij')
        xv = (xv[:, :, np.newaxis] - 0.5) * gt.shape[0] / args.f
        yv = (yv[:, :, np.newaxis] - 0.5) * gt.shape[1] / args.f

        X = np.concatenate((xv, yv, np.ones_like(xv)), axis=2)
        Z = np.sum(N * X, axis=2) * gt * 1000 + offset
        mask = np.zeros_like(gt)
        mask[Z > 0] = 0
        mask[Z < 0] = 255
        mask[gt < 0.01] = 255 // 2

        corner_flag = True
        j = 0
        best_score = 1.0
        while corner_flag:
            j += 1
            h_tmp = np.random.randint(Z.shape[0] - 128)
            w_tmp = np.random.randint(Z.shape[1] - 160)
            ROI = Z[h_tmp:h_tmp + 128, w_tmp:w_tmp + 160]
            score = np.abs(np.mean(ROI) / 255 - 0.5)
            if score < best_score:
                best_score = score
                h = h_tmp
                w = w_tmp
            if score < 0.25 or j > 100:
                corner_flag = False
                h = h_tmp
                w = w_tmp

        mask_color = 255 - mask[:, :, np.newaxis]
        mask_color = np.concatenate(
            (np.zeros_like(mask_color), mask_color, np.zeros_like(mask_color)),
            axis=2)
        mask_color = 0.8 * img + 0.2 * mask_color
        mask_color = draw_box(mask_color, h, w, color=[0, 128, 0])

        mask_path = os.path.join(
            'examples/tmp',
            'mask_' + str(i) + '_' + image.replace(os.sep, '_')).replace(
                '.dpt', '.png')
        cv_io.save(mask_path, mask_color.astype(np.uint8))

        mask_paths.append(mask_path)
        masks.append(mask)

    return mask_paths, masks
Esempio n. 8
0
    items = ['Examples are sorted based on the DR metric']
    items.append('Green rectangular is Region of Interest (ROI)')
    items.append('Final mask is a soft mask')
    items.append("Slide's title is combination of the image name and its DR values")
    items.append('Python generator code is available on \\href{https://github.com/saeid-h/Latex-Slides}{Github}')
    intro_slide = Items(items)
    slide = Frame('Introduction', intro_slide) 
    presentation.add_frames(slide)

    for i, image_tuple in enumerate(images):
        image, score = image_tuple
        title = image.split(os.sep)[-1].split('.')[0].replace('_', '\_') + ' ::: ' + str(round(score*100,2)) + '\%'
        scale = 0.15 if args.dataset == 'nyu' else 0.18 
        gt_path_abs = get_gt_path(image, args.dataset)
        gt = cv_io.read(gt_path_abs)

        rgb_path = os.path.join(args.data_path, 'rgb', image)
        rgb_path = ROI_box(rgb_path, args).replace('_', '\string_')
        rgb_img = Graphics(scale, path=rgb_path)

        gt_path = get_gt_temp(image, args)
        gt_path = ROI_box_gt(gt, rgb_path).replace('_', '\string_')
        gt_img =  Graphics(scale, path=gt_path) 

        mask_gt_path = get_gt_mask_temp(image, args)
        mask_gt_img = Graphics(scale=0.58, path=mask_gt_path)

        table_data = [[rgb_img, gt_img, mask_gt_img]]
        table_data += [['RGB', 'GT', 'GT Mask']]