Exemplo n.º 1
0
def plot_recErr_per_data(task, data_name, maskFlag, epochNums, resultname,
                         color, ax):
    gtpaths = returnGTPaths(task, data_name)
    s0paths = returnS0Paths(task, data_name)

    if maskFlag:
        maskpaths = returnMaskPaths(task, data_name)

    err_perEpoch = []
    for epochNum in epochNums:
        recpaths = returnRecPaths(task, resultname, epochNum, data_name)

        errs = np.empty(0, dtype=np.float32)
        for gtpath in gtpaths:
            s0path = find_same_id_s0(gtpath, s0paths)
            recpath = find_same_id(gtpath, recpaths)

            gt = cv2.imread(str(gtpath), -1).astype(np.float32)
            s0 = cv2.imread(str(s0path), -1).astype(np.float32)
            rec = cv2.imread(str(recpath), -1).astype(np.float32)

            # Calc masks
            noObj_mask = (np.sum(gt, axis=2) > 0)
            s0_mask = (np.sum(s0 / 3, axis=2) > params["s0threshold"])

            # Calc error
            ang_deg = calcAngError(gt, rec)

            # consider mask area
            if maskFlag:
                maskpath = find_same_id(gtpath, maskpaths)
                mask = cv2.imread(str(maskpath), -1).astype(np.float32)

                ang_deg = extractMaskArea(ang_deg, mask, maskFlag)
                noObj_mask = extractMaskArea(noObj_mask, mask, maskFlag)
                s0_mask = extractMaskArea(s0_mask, mask, maskFlag)

            ang_deg = ang_deg[noObj_mask * s0_mask]
            errs = np.append(errs, ang_deg)

        err_perEpoch.append(np.mean(errs))

    ax.plot(epochNums,
            err_perEpoch,
            label=data_name.split("/")[1],
            color=color,
            marker=shape)
    ax.legend(bbox_to_anchor=(1.05, 1), loc="upper left")
            errs = np.empty(0, dtype=np.float32)
            for gtpath in gtpaths:
                s0path = find_same_id_s0(gtpath, s0paths)
                recpath = find_same_id(gtpath, recpaths)

                gt = cv2.imread(str(gtpath), -1).astype(np.float32)
                s0 = cv2.imread(str(s0path), -1).astype(np.float32)
                rec = cv2.imread(str(recpath), -1).astype(np.float32)

                # Calc masks
                noObj_mask = (np.sum(gt, axis=2) > 0)
                s0_mask = (np.sum(s0 / 3, axis=2) > params["s0threshold"])

                # Calc error
                ang_deg = calcAngError(gt, rec)

                # consider mask area
                if maskFlag:
                    maskpath = find_same_id(gtpath, maskpaths)
                    mask = cv2.imread(str(maskpath), -1).astype(np.float32)

                    ang_deg = extractMaskArea(ang_deg, mask, maskFlag)
                    noObj_mask = extractMaskArea(noObj_mask, mask, maskFlag)
                    s0_mask = extractMaskArea(s0_mask, mask, maskFlag)

                ang_deg = ang_deg[noObj_mask * s0_mask]

                mn, std = np.mean(ang_deg), np.std(ang_deg)
                errs = np.append(errs, ang_deg)
Exemplo n.º 3
0
    s0path = find_same_id_s0(gtpath, s0paths)

    # load images
    gt = cv2.imread(str(gtpath), -1).astype(np.float32)
    recon = cv2.imread(str(recpath), -1).astype(np.float32)
    s0 = cv2.imread(str(s0path), -1).astype(np.float32)

    # mask pixels which do not have any values
    noObj_mask = (np.sum(gt, axis=2) > 0)
    # mask pixels whose values are smaller than threshold
    s0_Darkmask = (np.sum(s0 / 3, axis=2) > params["s0threshold"])
    s0_Whitemask = (s0[:, :, 0] < MAX_16BIT) + (s0[:, :, 1] < MAX_16BIT) + (
        s0[:, :, 2] < MAX_16BIT)

    # calc error
    ang_deg = nm.calcAngError(gt, recon)
    #calc gt zenith
    zenith_deg = nm.calcZenithDegMap(gt[:, :, ::-1])
    # calc depth error
    depth_err = nm.normalErr2depthErr(zenith_deg, ang_deg)

    # prepare figure
    fig = plt.figure(figsize=(9, 4.5))
    gs = gridspec.GridSpec(3,
                           3,
                           height_ratios=[1, 1, 1],
                           width_ratios=[4, 1, 1])
    ax_main = plt.subplot(gs[:, 0])

    # prepare cmap
    cmap = mpl.cm.jet