Ejemplo n.º 1
0
    def _runImp(self):
        normal_data = loadNormal(self._data_file)

        if normal_data is None:
            return

        N0_32F, A_8U = normal_data

        # N0_32F = cv2.resize(N0_32F, (64, 64))
        # A_8U = cv2.resize(A_8U, N0_32F.shape[:2])

        A_32F = to32F(A_8U)

        L = normalizeVector(np.array([-0.2, 0.3, 0.7]))

        # C0_32F = ToonShader().diffuseShading(L, N0_32F)
        C0_32F = LambertShader().diffuseShading(L, N0_32F)

        sfs_method = Wu08SFS(L, C0_32F, A_8U)
        sfs_method.run()
        N_32F = sfs_method.normal()

        saveNormal(self.resultFile(self._data_file_name, result_name="Wu08"), N_32F, A_8U)

        C_error = sfs_method.shadingError()
        I_32F = sfs_method.brightness()
        I_32F = gray2rgb(I_32F)
        C_32F = sfs_method.shading()

        N0_32F = trim(N0_32F, A_8U)
        C0_32F = trim(C0_32F, A_8U)
        C_32F = trim(C_32F, A_8U)
        N_32F = trim(N_32F, A_8U)
        C_error = trim(C_error, A_8U)
        I_32F = trim(I_32F, A_8U)
        A_32F = trim(A_32F, A_8U)
        A_8U = trim(A_8U, A_8U)

        h, w = N_32F.shape[:2]
        N_error = angleErros(N_32F.reshape(-1, 3), N0_32F.reshape(-1, 3)).reshape(h, w)
        N_error[A_8U < np.max(A_8U)] = 0.0

        fig, axes = plt.subplots(figsize=(11, 5))
        font_size = 15
        fig.subplots_adjust(left=0.05, right=0.95, top=0.9, hspace=0.12, wspace=0.05)
        fig.suptitle(self.name(), fontsize=font_size)

        num_rows = 2
        num_cols = 3
        plot_grid = SubplotGrid(num_rows, num_cols)

        plot_grid.showImage(normalToColor(N0_32F, A_8U), r"Ground Truth Normal: $N_g$")
        plot_grid.showImage(normalToColor(N_32F, A_8U), r"Estimated Normal: $N$")
        plot_grid.showColorMap(N_error, r"Angle Error: $N_g, N$", v_min=0, v_max=30.0)

        plot_grid.showImage(setAlpha(C0_32F, A_32F), r"Shading: $C$")
        plot_grid.showImage(setAlpha(C_32F, A_32F), r"Estimated Shading: $C$")
        plot_grid.showColorMap(C_error, r"Shading Error: $C_g, C$", v_min=0, v_max=0.1)

        showMaximize()
Ejemplo n.º 2
0
    def _runImp(self):
        normal_data = loadNormal(self._data_file)

        if normal_data is None:
            return

        N0_32F, A_8U = normal_data

        #N0_32F = cv2.resize(N0_32F, (64, 64))
        #A_8U = cv2.resize(A_8U, N0_32F.shape[:2])

        A_32F = to32F(A_8U)

        L = normalizeVector(np.array([-0.2, 0.3, 0.7]))

        # C0_32F = ToonShader().diffuseShading(L, N0_32F)
        C0_32F = LambertShader().diffuseShading(L, N0_32F)

        sfs_method = Wu08SFS(L, C0_32F, A_8U)
        sfs_method.run()
        N_32F = sfs_method.normal()

        saveNormal(self.resultFile(self._data_file_name, result_name="Wu08"), N_32F, A_8U)

        C_error = sfs_method.shadingError()
        I_32F = sfs_method.brightness()
        I_32F = gray2rgb(I_32F)
        C_32F = sfs_method.shading()

        N0_32F = trim(N0_32F, A_8U)
        C0_32F = trim(C0_32F, A_8U)
        C_32F = trim(C_32F, A_8U)
        N_32F = trim(N_32F, A_8U)
        C_error = trim(C_error, A_8U)
        I_32F = trim(I_32F, A_8U)
        A_32F = trim(A_32F, A_8U)
        A_8U = trim(A_8U, A_8U)

        h, w = N_32F.shape[:2]
        N_error = angleErros(N_32F.reshape(-1, 3), N0_32F.reshape(-1, 3)).reshape(h, w)
        N_error[A_8U < np.max(A_8U)] = 0.0

        fig, axes = plt.subplots(figsize=(11, 5))
        font_size = 15
        fig.subplots_adjust(left=0.05, right=0.95, top=0.9, hspace=0.12, wspace=0.05)
        fig.suptitle(self.name(), fontsize=font_size)

        num_rows = 2
        num_cols = 3
        plot_grid = SubplotGrid(num_rows, num_cols)

        plot_grid.showImage(normalToColor(N0_32F, A_8U), r'Ground Truth Normal: $N_g$')
        plot_grid.showImage(normalToColor(N_32F, A_8U), r'Estimated Normal: $N$')
        plot_grid.showColorMap(N_error, r'Angle Error: $N_g, N$', v_min=0, v_max=30.0)

        plot_grid.showImage(setAlpha(C0_32F, A_32F), r'Shading: $C$')
        plot_grid.showImage(setAlpha(C_32F, A_32F), r'Estimated Shading: $C$')
        plot_grid.showColorMap(C_error, r'Shading Error: $C_g, C$', v_min=0, v_max=0.1)

        showMaximize()
Ejemplo n.º 3
0
    def _runImp(self):
        normal_data = loadNormal(self._data_file)

        if normal_data is None:
            return

        N_32F, A_8U = normal_data

        N_32F = trim(N_32F, A_8U)
        A_8U = trim(A_8U, A_8U)
        A_32F = to32F(A_8U)

        L = normalizeVector(np.array([-0.2, 0.3, 0.7]))

        I_half = half_lambert.diffuse(N_32F, L)
        I_half = setAlpha(gray2rgb(I_half), A_32F)

        I_lambert = lambert.diffuse(N_32F, L)
        I_lambert = setAlpha(gray2rgb(I_lambert), A_32F)

        fig, axes = plt.subplots(figsize=(11, 5))

        font_size = 15

        fig.subplots_adjust(left=0.05,
                            right=0.95,
                            top=0.9,
                            hspace=0.05,
                            wspace=0.05)
        fig.suptitle("Depth From Normal", fontsize=font_size)

        plt.subplot(1, 4, 1)
        plt.title(r'Normal: $N$')
        plt.imshow(normalToColor(N_32F, A_8U))
        plt.axis('off')

        plt.subplot(1, 4, 2)
        plt.title(r'Half Lambert: $I_h$')
        plt.imshow(I_half)
        plt.axis('off')

        plt.subplot(1, 4, 3)
        plt.title(r'Lambert: $I_l$')
        plt.imshow(I_lambert)
        plt.axis('off')

        showMaximize()
Ejemplo n.º 4
0
 def depthImage(self):
     D_min = np.min(self._depth)
     D_max = np.max(self._depth)
     D_32F = (self._depth - D_min) / (D_max - D_min)
     D_8U = to8U(D_32F)
     D_8U = gray2rgb(D_8U)
     A_8U = alpha(self._image)
     D_8U = setAlpha(D_8U, A_8U)
     return D_8U
Ejemplo n.º 5
0
    def _runImp(self):
        normal_data = loadNormal(self._data_file)

        if normal_data is None:
            return

        N_32F, A_8U = normal_data

        N_32F = trim(N_32F, A_8U)
        A_8U = trim(A_8U, A_8U)
        A_32F = to32F(A_8U)

        L = normalizeVector(np.array([-0.2, 0.3, 0.7]))

        I_half = half_lambert.diffuse(N_32F, L)
        I_half = setAlpha(gray2rgb(I_half), A_32F)

        I_lambert = lambert.diffuse(N_32F, L)
        I_lambert = setAlpha(gray2rgb(I_lambert), A_32F)

        fig, axes = plt.subplots(figsize=(11, 5))

        font_size = 15

        fig.subplots_adjust(left=0.05, right=0.95, top=0.9, hspace=0.05, wspace=0.05)
        fig.suptitle("Depth From Normal", fontsize=font_size)

        plt.subplot(1, 4, 1)
        plt.title(r'Normal: $N$')
        plt.imshow(normalToColor(N_32F, A_8U))
        plt.axis('off')

        plt.subplot(1, 4, 2)
        plt.title(r'Half Lambert: $I_h$')
        plt.imshow(I_half)
        plt.axis('off')

        plt.subplot(1, 4, 3)
        plt.title(r'Lambert: $I_l$')
        plt.imshow(I_lambert)
        plt.axis('off')

        showMaximize()
Ejemplo n.º 6
0
def ndarrayToQImage(img):
    C_8U = to8U(img)

    if len(C_8U.shape) == 2:
        C_8U = gray2rgb(C_8U)

    if C_8U.shape[2] == 2:
        C_8U = rg_to_rgb(C_8U)

    if C_8U.shape[2] == 3:
        return rgb_to_Qrgb(C_8U)

    if C_8U.shape[2] == 4:
        return rgba_to_Qargb(C_8U)

    return QImage()
def computeIllumination(L, N_32F, A_8U):
    I_32F = np.clip(LdotN(L, N_32F), 0.0, 1.0)
    I_32F[A_8U < 0.5 * np.max(A_8U)] = 0.0
    I_32F = setAlpha(gray2rgb(to8U(I_32F)), A_8U)
    I_32F = trim(I_32F, A_8U)
    return I_32F
def overviewFigure():
    cmap_id = 10
    colormap_file = colorMapFile(cmap_id)

    num_rows = 1
    num_cols = 5

    w = 10
    h = w * num_rows / num_cols

    fig, axes = plt.subplots(figsize=(w, h))
    font_size = 15
    fig.subplots_adjust(left=0.02, right=0.98, top=0.96, bottom=0.02, hspace=0.05, wspace=0.05)
    fig.suptitle("", fontsize=font_size)

    plot_grid = SubplotGrid(num_rows, num_cols)

    L = normalizeVector(np.array([-0.4, 0.6, 0.6]))
    L_img = lightSphere(L)

    shape_name = "ThreeBox"

    Ng_data = shapeFile(shape_name)
    Ng_data = loadNormal(Ng_data)
    Ng_32F, A_8U = Ng_data

    N0_file = shapeResultFile(result_name="InitialNormal", data_name=shape_name)
    N0_data = loadNormal(N0_file)
    N0_32F, A_8U = N0_data

    M_32F = loadColorMap(colormap_file)
    Cg_32F = ColorMapShader(M_32F).diffuseShading(L, Ng_32F)

    borders=[0.6, 0.8, 0.92]
    colors = [np.array([0.2, 0.2, 0.4]),
              np.array([0.3, 0.3, 0.6]),
              np.array([0.4, 0.4, 0.8]),
              np.array([0.5, 0.5, 1.0])]
    #Cg_32F = ToonShader(borders, colors).diffuseShading(L, Ng_32F)
    #Cg_32F = cv2.GaussianBlur(Cg_32F, (0,0), 2.0)

    sfs_method = ToonSFS(L, Cg_32F, A_8U)
    sfs_method.setInitialNormal(N0_32F)
    sfs_method.setNumIterations(iterations=40)
    sfs_method.setWeights(w_lap=10.0)
    sfs_method.run()

    N_32F = sfs_method.normal()
    I_32F = np.float32(np.clip(LdotN(L, N_32F), 0.0, 1.0))
    I0_32F = np.float32(np.clip(LdotN(L, N0_32F), 0.0, 1.0))
    C_32F = sfs_method.shading()
    C0_32F = sfs_method.initialShading()

    M_32F = sfs_method.colorMap().mapImage()

    L1 = normalizeVector(np.array([0.0, 0.6, 0.6]))
    L1_img = lightSphere(L1)
    C1_32F = sfs_method.relighting(L1)

    L2 = normalizeVector(np.array([0.5, 0.8, 0.6]))
    L2_img = lightSphere(L2)
    C2_32F = sfs_method.relighting(L2)

    N_sil = silhouetteNormal(A_8U, sigma=7.0)
    N_sil[:, :, 2]  = N_sil[:, :, 2] ** 10.0
    N_sil = normalizeImage(N_sil)
    A_sil = 1.0 - N_sil[:, :, 2]
    A_sil = to8U(A_sil)
    N_xy = N_sil[:, :, 0] ** 2 + N_sil[:, :, 1] ** 2
    A_sil[N_xy < 0.1] = 0

    title = ""
    plot_grid.showImage(setAlpha(Cg_32F, to32F(A_8U)), title)
    plot_grid.showImage(normalToColor(N0_32F, A_8U), title)
    plot_grid.showImage(setAlpha(C0_32F, to32F(A_8U)), title)
    plot_grid.showImage(normalToColor(N_32F, A_8U), title)

    plot_grid.showImage(setAlpha(C_32F, to32F(A_8U)), title)
    # plot_grid.showImage(normalToColor(Ng_32F, A_8U), title)

    #showMaximize()
    file_path = shapeResultFile("Overview", "Overview")
    fig.savefig(file_path, transparent=True)

    file_path = shapeResultFile("Overview", "Cg")
    saveRGBA(file_path, setAlpha(Cg_32F, to32F(A_8U)))

    file_path = shapeResultFile("Overview", "L")
    saveRGB(file_path, gray2rgb(to8U(L_img)))

    file_path = shapeResultFile("Overview", "L1")
    saveRGB(file_path, gray2rgb(to8U(L1_img)))

    file_path = shapeResultFile("Overview", "L2")
    saveRGB(file_path, gray2rgb(to8U(L2_img)))

    file_path = shapeResultFile("Overview", "N0")
    saveNormal(file_path, N0_32F, A_8U)

    file_path = shapeResultFile("Overview", "N_sil")
    saveNormal(file_path, N_sil, A_sil)

    file_path = shapeResultFile("Overview", "N")
    saveNormal(file_path, N_32F, A_8U)

    file_path = shapeResultFile("Overview", "C0")
    saveRGBA(file_path, setAlpha(C0_32F, to32F(A_8U)))

    file_path = shapeResultFile("Overview", "C")
    saveRGBA(file_path, setAlpha(C_32F, to32F(A_8U)))

    file_path = shapeResultFile("Overview", "C1")
    saveRGBA(file_path, setAlpha(C1_32F, to32F(A_8U)))

    file_path = shapeResultFile("Overview", "C2")
    saveRGBA(file_path, setAlpha(C2_32F, to32F(A_8U)))

    file_path = shapeResultFile("Overview", "I")
    saveRGBA(file_path, setAlpha(gray2rgb(I_32F), to32F(A_8U)))

    file_path = shapeResultFile("Overview", "I0")
    saveRGBA(file_path, setAlpha(gray2rgb(I0_32F), to32F(A_8U)))

    file_path = shapeResultFile("Overview", "M")
    saveRGB(file_path, M_32F)
def computeIllumination(L, N_32F, A_8U):
    I_32F = np.clip(LdotN(L, N_32F), 0.0, 1.0)
    I_32F[A_8U < 0.5 * np.max(A_8U)] = 0.0
    I_32F = setAlpha(gray2rgb(to8U(I_32F)), A_8U)
    I_32F = trim(I_32F, A_8U)
    return I_32F