コード例 #1
0
def materialErrorTable():
    shape_name = "ThreeBox"

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

    num_materials = len(colorMapFiles())
    C_errors = np.zeros((num_materials, 3))
    N_errors = np.zeros((num_materials, 3))
    I_errors = np.zeros((num_materials, 3))

    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
    A_8U = cv2.bilateralFilter(A_8U, 0, 5, 2)

    for mi, color_map_file in enumerate(colorMapFiles()):
        M_32F = loadColorMap(color_map_file)

        C0_32F = ColorMapShader(M_32F).diffuseShading(L, Ng_32F)

        toon_sfs = ToonSFS(L, C0_32F, A_8U)
        toon_sfs.setInitialNormal(N0_32F)
        toon_sfs.setNumIterations(iterations=20)
        toon_sfs.setWeights(w_lap=9.0)
        toon_sfs.run()

        N_toon = toon_sfs.normal()
        C_toon = toon_sfs.shading()

        C_lumo, N_lumo = lumoSFS(C0_32F, L, N0_32F, A_8U)
        C_wu, N_wu = wuSFS(C0_32F, L, N0_32F, A_8U)

        C_error_toon, N_error_toon, I_error_toon = computeErrors(L, C0_32F, C_toon, Ng_32F, N_toon, A_8U)
        C_error_lumo, N_error_lumo, I_error_lumo = computeErrors(L, C0_32F, C_lumo, Ng_32F, N_lumo, A_8U)
        C_error_wu, N_error_wu, I_error_wu = computeErrors(L, C0_32F, C_wu, Ng_32F, N_wu, A_8U)

        C_errors[mi, 0] = np.mean(C_error_toon)
        C_errors[mi, 1] = np.mean(C_error_lumo)
        C_errors[mi, 2] = np.mean(C_error_wu)

        I_errors[mi, 0] = np.mean(I_error_toon)
        I_errors[mi, 1] = np.mean(I_error_lumo)
        I_errors[mi, 2] = np.mean(I_error_wu)

        N_errors[mi, 0] = np.mean(N_error_toon)
        N_errors[mi, 1] = np.mean(N_error_lumo)
        N_errors[mi, 2] = np.mean(N_error_wu)

    file_path = shapeResultFile("ShapeEstimation", "MaterialShadingError", file_ext=".npy")
    np.save(file_path, C_errors)

    file_path = shapeResultFile("ShapeEstimation", "MaterialNormalError", file_ext=".npy")
    np.save(file_path, N_errors)

    file_path = shapeResultFile("ShapeEstimation", "MaterialIlluminationError", file_ext=".npy")
    np.save(file_path, I_errors)
コード例 #2
0
def materialList():
    shape_name = "ThreeBox"
    num_rows = 1
    num_cols = len(colorMapFiles())

    w = 24
    h = w * num_rows / num_cols

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

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

    plot_grid = SubplotGrid(num_rows, num_cols)

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

    for colormap_file in colorMapFilesSortedReflectanceError():
        M_32F = loadColorMap(colormap_file)

        C0_32F = ColorMapShader(M_32F).diffuseShading(L, Ng_32F)

        plot_grid.showImage(setAlpha(C0_32F, to32F(A_8U)), "")

    file_path = shapeResultFile("ShapeEstimation", "MaterialList")
    fig.savefig(file_path, transparent=True)
コード例 #3
0
def materialList():
    shape_name = "ThreeBox"
    num_rows = 1
    num_cols = len(colorMapFiles())

    w = 24
    h = w * num_rows / num_cols

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

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

    plot_grid = SubplotGrid(num_rows, num_cols)

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

    for colormap_file in colorMapFilesSortedReflectanceError():
        M_32F = loadColorMap(colormap_file)


        C0_32F = ColorMapShader(M_32F).diffuseShading(L, Ng_32F)

        plot_grid.showImage(setAlpha(C0_32F, to32F(A_8U)), "")

    file_path = shapeResultFile("ShapeEstimation", "MaterialList")
    fig.savefig(file_path, transparent=True)
コード例 #4
0
def colorMapFigure():
    L = normalizeVector(np.array([-0.2, 0.3, 0.7]))
    N_32F, A_32F = normalSphere(h=512, w=512)

    fig, axes = plt.subplots(figsize=(6, 4))
    font_size = 15
    fig.subplots_adjust(left=0.02,
                        right=0.98,
                        top=0.98,
                        bottom=0.02,
                        hspace=0.1,
                        wspace=0.1)
    fig.suptitle("", fontsize=font_size)

    num_rows = 4
    num_cols = 6
    plot_grid = SubplotGrid(num_rows, num_cols)

    for colormap_file in colorMapFiles():
        M_32F = loadColorMap(colormap_file)
        C_32F = ColorMapShader(M_32F).diffuseShading(L, N_32F)
        plot_grid.showImage(setAlpha(C_32F, A_32F), "")

    file_path = os.path.join(colorMapResultsDir(), "ColorMapMaterials.png")
    fig.savefig(file_path, transparent=True)
コード例 #5
0
def errorInfo():
    colormap_files = colorMapFiles()
    shape_names = shapeNames()

    num_materials = len(colormap_files)
    num_shapes = len(shape_names)

    file_path = shapeResultFile("LightEstimation", "LightEstimationError", file_ext=".npy")
    L_errors = np.load(file_path)

    shape_errors = np.zeros(num_shapes)
    for si, shape_name in enumerate(shape_names):
        shape_errors[si] = np.average(L_errors[si, :])

    shape_error_orders = np.argsort(shape_errors)
    print shape_error_orders
    print shape_error_orders[:3]
    print shape_error_orders[-3:]

    for shape_error_order in shape_error_orders[:3]:
        print shape_names[shape_error_order]

    for shape_error_order in shape_error_orders[-3:]:
        print shape_names[shape_error_order]

    material_errors = np.zeros(num_materials)
    for mi in xrange(num_materials):
        material_errors[mi] = np.average(L_errors[:, mi])

    material_error_orders = np.argsort(material_errors)

    print material_error_orders[:3]
    print material_error_orders[-3:]
コード例 #6
0
def computeErrorTables(Lg=normalizeVector(np.array([-0.2, 0.3, 0.6]))):
    colormap_files = colorMapFiles()
    shape_names = shapeNames()

    num_materials = len(colormap_files)
    num_shapes = len(shape_names)

    L_errors = np.zeros((num_shapes, num_materials))

    Ms = []
    for colormap_file in colormap_files:
        M_32F = loadColorMap(colormap_file)
        Ms.append(M_32F)

    for si, shape_name in enumerate(shape_names):
        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

        for mi, M_32F in enumerate(Ms):
            C0_32F = ColorMapShader(M_32F).diffuseShading(Lg, Ng_32F)
            I_32F = luminance(C0_32F)

            L = lightEstimation(I_32F, N0_32F, A_8U)

            L_errors[si, mi] = angleError(Lg, L)

    file_path = shapeResultFile("LightEstimation", "LightEstimationError", file_ext=".npy")
    np.save(file_path, L_errors)
コード例 #7
0
def colorMapRename():
    cmap_id = 0

    for colormap_file in colorMapFiles():
        if os.path.exists(colorMapFile(cmap_id)):
            cmap_id += 1
            continue

        os.rename(colormap_file, colorMapFile(cmap_id))
        cmap_id += 1
コード例 #8
0
def colorMapRename():
    cmap_id = 0

    for colormap_file in colorMapFiles():
        if os.path.exists(colorMapFile(cmap_id)):
            cmap_id += 1
            continue

        os.rename(colormap_file, colorMapFile(cmap_id))
        cmap_id += 1
コード例 #9
0
    def _runImp(self):
        N0_file = shapeResultFile(result_name="InitialNormal", data_name=self._data_name)
        N0_data = loadNormal(N0_file)

        N0_32F, A_8U = N0_data

        Ng_data = loadNormal(self._data_file)
        Ng_32F, A_8U = Ng_data

        for colormap_file in colorMapFiles():
            self._runColorMap(colormap_file, Ng_32F, N0_32F, A_8U)
コード例 #10
0
    def _runImp(self):
        N0_file = shapeResultFile(result_name="InitialNormal",
                                  data_name=self._data_name)
        N0_data = loadNormal(N0_file)

        N0_32F, A_8U = N0_data

        Ng_data = loadNormal(self._data_file)
        Ng_32F, A_8U = Ng_data

        for colormap_file in colorMapFiles():
            self._runColorMap(colormap_file, Ng_32F, N0_32F, A_8U)
コード例 #11
0
def colorMapFigure():
    L = normalizeVector(np.array([-0.2, 0.3, 0.7]))
    N_32F, A_32F = normalSphere(h=512, w=512)

    fig, axes = plt.subplots(figsize=(6, 4))
    font_size = 15
    fig.subplots_adjust(left=0.02, right=0.98, top=0.98, bottom=0.02, hspace=0.1, wspace=0.1)
    fig.suptitle("", fontsize=font_size)

    num_rows = 4
    num_cols = 6
    plot_grid = SubplotGrid(num_rows, num_cols)

    for colormap_file in colorMapFiles():
        M_32F = loadColorMap(colormap_file)
        C_32F = ColorMapShader(M_32F).diffuseShading(L, N_32F)
        plot_grid.showImage(setAlpha(C_32F, A_32F), "")

    file_path = os.path.join(colorMapResultsDir(), "ColorMapMaterials.png")
    fig.savefig(file_path, transparent=True)
コード例 #12
0
def errorTable():
    colormap_files = colorMapFiles()
    num_colormap_files = len(colormap_files)
    M_errors = np.zeros((num_colormap_files))

    for mi, colormap_file in enumerate(colormap_files):
        M_32F = loadColorMap(colormap_file)
        C_32F = M_32F.reshape(1, len(M_32F), 3)

        I_32F = np.linspace(0.0, 1.0, len(M_32F))
        I_32F = I_32F.reshape(C_32F.shape[:2])
        reflectance = LambertReflectanceEstimation(C_32F, I_32F)
        Ml = reflectance.shading(I_32F)[0, :, :]

        I0_32F = luminance(C_32F)
        IL_32F = luminance(Ml.reshape(1, -1, 3))

        I_min, I_max = np.min(I0_32F), np.max(I0_32F)

        M_error = normVectors(M_32F - Ml)

        #M_errors[mi] = np.mean(M_error) / (I_max - I_min)

        # M_errors[mi] = computeGradientDistance(M_32F, Ml) / (I_max - I_min)

        #M_errors[mi] = np.linalg.norm(I0_32F - IL_32F) / (I_max - I_min)

        M_errors[mi] = np.mean(M_error) / (I_max - I_min)

        # M_errors[mi] = np.linalg.norm(M_32F - Ml) / (I_max - I_min)
        # M_errors[mi] = compareHist(M_32F, Ml)

    file_path = shapeResultFile("ReflectanceEstimation", "ReflectanceError", file_ext=".npy")
    np.save(file_path, M_errors)

    plt.plot(M_errors)
    plt.show()
コード例 #13
0
def colorMapFilesSortedReflectanceError():
    M_error_orders = reflectanceErrorOrders()
    colormap_files = colorMapFiles()
    colormap_files = [colormap_files[M_error_order] for M_error_order in M_error_orders]

    return colormap_files
コード例 #14
0
def reflectanceEstimationFigure():
    errorTable()
    M_errors = loadReflectanceErrorTable()
    M_error_orders = np.argsort(M_errors)

    print M_errors[M_error_orders]

    colormap_files = colorMapFiles()
    colormap_files = [colormap_files[M_error_order] for M_error_order in M_error_orders]

    colormap_files = colormap_files[0:-1:3]

    Ms = []
    MLs = []
    for colormap_file in colormap_files:
        M_32F = loadColorMap(colormap_file)
        Ms.append(M_32F)

        C_32F = M_32F.reshape(1, len(M_32F), 3)
        I_32F = np.linspace(0.0, 1.0, len(M_32F))
        I_32F = I_32F.reshape(C_32F.shape[:2])
        reflectance = LambertReflectanceEstimation(C_32F, I_32F)
        Ml = reflectance.shading(I_32F)

        MLs.append(Ml[0, :, :])

    num_rows = 3
    num_cols = len(colormap_files)

    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.98, bottom=0.02, hspace=0.05, wspace=0.05)
    fig.suptitle("", fontsize=font_size)

    N_sphere, A_32F = normalSphere(h=512, w=512)
    Lg = normalizeVector(np.array([-0.2, 0.3, 0.6]))

    plot_grid = SubplotGrid(num_rows, num_cols)

    mi = 1

    for M, Ml in zip(Ms, MLs):
        CM_32F = ColorMapShader(M).diffuseShading(Lg, N_sphere)
        CL_32F = ColorMapShader(Ml).diffuseShading(Lg, N_sphere)
        C_error = normVectors((CM_32F - CL_32F).reshape(-1, 3)).reshape(CL_32F.shape[:2])
        C_error[A_32F < 0.5 * np.max(A_32F)] = 0.0

        plot_grid.setPlot(1, mi)
        plot_grid.showImage(setAlpha(CM_32F, A_32F), "")
        plot_grid.setPlot(2, mi)
        plot_grid.showImage(setAlpha(CL_32F, A_32F), "")
        plot_grid.setPlot(3, mi)
        plot_grid.showColorMap(C_error, "", v_min=0.0, v_max=0.3, with_colorbar=False)

        mi += 1

    file_path = shapeResultFile("ReflectanceEstimation", "ReflectanceEstimationError")
    fig.savefig(file_path, transparent=True)
コード例 #15
0
def materialErrorTable():
    shape_name = "ThreeBox"

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

    num_materials = len(colorMapFiles())
    C_errors = np.zeros((num_materials, 3))
    N_errors = np.zeros((num_materials, 3))
    I_errors = np.zeros((num_materials, 3))

    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
    A_8U = cv2.bilateralFilter(A_8U, 0, 5, 2)

    for mi, color_map_file in enumerate(colorMapFiles()):
        M_32F = loadColorMap(color_map_file)

        C0_32F = ColorMapShader(M_32F).diffuseShading(L, Ng_32F)

        toon_sfs = ToonSFS(L, C0_32F, A_8U)
        toon_sfs.setInitialNormal(N0_32F)
        toon_sfs.setNumIterations(iterations=20)
        toon_sfs.setWeights(w_lap=9.0)
        toon_sfs.run()

        N_toon = toon_sfs.normal()
        C_toon = toon_sfs.shading()

        C_lumo, N_lumo = lumoSFS(C0_32F, L, N0_32F, A_8U)
        C_wu, N_wu = wuSFS(C0_32F, L, N0_32F, A_8U)

        C_error_toon, N_error_toon, I_error_toon = computeErrors(
            L, C0_32F, C_toon, Ng_32F, N_toon, A_8U)
        C_error_lumo, N_error_lumo, I_error_lumo = computeErrors(
            L, C0_32F, C_lumo, Ng_32F, N_lumo, A_8U)
        C_error_wu, N_error_wu, I_error_wu = computeErrors(
            L, C0_32F, C_wu, Ng_32F, N_wu, A_8U)

        C_errors[mi, 0] = np.mean(C_error_toon)
        C_errors[mi, 1] = np.mean(C_error_lumo)
        C_errors[mi, 2] = np.mean(C_error_wu)

        I_errors[mi, 0] = np.mean(I_error_toon)
        I_errors[mi, 1] = np.mean(I_error_lumo)
        I_errors[mi, 2] = np.mean(I_error_wu)

        N_errors[mi, 0] = np.mean(N_error_toon)
        N_errors[mi, 1] = np.mean(N_error_lumo)
        N_errors[mi, 2] = np.mean(N_error_wu)

    file_path = shapeResultFile("ShapeEstimation",
                                "MaterialShadingError",
                                file_ext=".npy")
    np.save(file_path, C_errors)

    file_path = shapeResultFile("ShapeEstimation",
                                "MaterialNormalError",
                                file_ext=".npy")
    np.save(file_path, N_errors)

    file_path = shapeResultFile("ShapeEstimation",
                                "MaterialIlluminationError",
                                file_ext=".npy")
    np.save(file_path, I_errors)