Пример #1
0
    def __init__(self, p, q):
        self._p = np.array(p)
        self._q = np.array(q)
        peq = np.array([p[0], p[1], 1])
        qeq = np.array([q[0], q[1], 1])
        self._n = np.cross(peq, qeq)
        self._n = normalizeVector(self._n)

        self._e = self._q - self._p
        self._e = normalizeVector(self._e)
        self._bb = BoundingBox([p, q])
def estimateResultFunc(data_name, target_name, N_32F, L_g, I_32F, A_8U, method_name, estimate_func):
    L_g = normalizeVector(L_g)
    silhouette_curve, S_8U = silhoutteCurve(A_8U)
    N_sil = silhouetteNormal(A_8U)
    silhouette_curve.setNormalImage(N_sil)

    N_sil = silhouette_curve.normals()

    cvs_sil = silhouette_curve.CVs()

    I_sil = np.array([I_32F[cv[1], cv[0]] for cv in cvs_sil])

    input_data = {"N_sil": N_sil, "I_sil": I_sil, "cvs_sil": cvs_sil, "I": I_32F, "A": A_8U}

    fig = plt.figure(figsize=(8, 8))
    fig.suptitle("Light estimation: %s" % method_name)
    fig.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.82, wspace=0.02, hspace=0.4)

    plt.subplot(2, 2, 1)
    plt.title("Ground truth")
    showLightSphere(plt, L_g)
    plt.axis("off")

    plt.subplot(2, 2, 2)
    plt.title("Illumination")

    A_32F = to32F(A_8U)
    I_org = I_32F * A_32F
    plt.gray()
    plt.imshow(I_org)
    plt.axis("off")

    output_data = estimate_func(input_data)
    L = output_data["L"]
    L = normalizeVector(L)
    L_error = angleError(L_g, L)
    plt.subplot(2, 2, 3)
    plt.title("Estimated error\n %4.1f $^\circ$" % L_error)
    showLightSphere(plt, L)
    plt.axis("off")

    I_est = lambert.diffuse(N_32F, L) * A_32F
    plt.subplot(2, 2, 4)
    plt.gray()
    plt.imshow(I_est)
    plt.axis("off")

    result_dir = resultDir("LightEstimation/%s" % data_name)
    result_file = resultFile(result_dir, "%s_%s" % (target_name, method_name))
    plt.savefig(result_file)
def estimateLbyDistance(cvs_sil, N_sil, I_32F):
    I_sampling = PixelSampling(I_32F, num_pixels = 10000)
    I_samples = I_sampling.pixels()
    I_coords = I_sampling.coordinates()

    I_large_ids = I_samples > 0.5 * np.max(I_samples)
#     I_max_id = np.argmax(I_samples)
#     I_max_coord = I_coords[I_max_id]
#
#     print I_max_coord, I_samples[I_max_id], np.max(I_samples)
    L = np.array([0.0, 0.0, 0.0])
    hist = 0.0
    for I_large_id in I_large_ids:
        I_coord = I_coords[I_large_id]
        dist = normVectors(cvs_sil - I_coord)
        dist_max = np.max(dist)
        w = np.exp(- (dist ** 2) / (0.2 * dist_max**2))
        w *= 1.0 / np.sum(w)

        L_i = np.dot(w, N_sil)
        L += L_i
        hist += 1.0

    if hist > 0.0:
        L /= hist
    print L

    Lz = np.sqrt(1.0 - np.dot(L, L))
    L[2] = Lz
    print L.shape
    L = normalizeVector(L)
    return L
def testToon(method_name, estimate_func):
    L_g = normalizeVector(np.array([-0.5, 0.7, 0.5]))

    for data_name in normal.dataNames():
        N_32F, A_8U = normal.loadData(data_name)
        C_32F = toondata.loadData(data_name, L_g)

        I_32F = luminance(C_32F[:, :, :3])
        estimateResultFunc(data_name, "Toon", N_32F, L_g, I_32F, A_8U, method_name, estimate_func)
Пример #5
0
 def __init__(self, L=[0.3, 0.5, 0.7], I=0.7, Ns=[]):
     self._L = normalizeVector(np.array(L))
     self._I = I
     self._Ns = Ns
     self._Lxyz = coordinateFrame(self._L)
     self.computeCone()
     self.computeAxisCenter()
     self.computeConeAngles()
     self.computeConeAngleChanges()
Пример #6
0
def diffuse(N_32F, L):
    L = normalizeVector(L)
    h, w, cs = N_32F.shape

    N_flat = N_32F.reshape((-1, 3))

    I_flat = np.dot(N_flat, L)
    I_32F = I_flat.reshape((h, w))
    I_32F = 0.5 * I_32F + 0.5
    return I_32F
Пример #7
0
def diffuse(N_32F, L):
    L = normalizeVector(L)
    h, w, cs = N_32F.shape

    N_flat = N_32F.reshape((-1, 3))

    I_flat = np.dot(N_flat, L)
    I_32F = I_flat.reshape((h, w))
    I_32F = np.clip(I_32F, 0.0, 1.0)
    return I_32F
Пример #8
0
def estimateLightByCluster(N_lumo, I_32F, p_samples):
    xs, ys = p_samples.T
    Is = I_32F[ys, xs]
    Ns = N_lumo[ys, xs, :]

    I_ids = luminanceClusters(Is)

    I_id_max = np.max(I_ids)

    Ns_bright = Ns[I_ids == I_id_max, :]
    L = np.sum(Ns_bright, axis=0)
    L = normalizeVector(L)
    print L
    return L
Пример #9
0
def diffuse(N_32F, L, borders=[0.5], colors=[np.array([0.2, 0.2, 0.5]), np.array([0.5, 0.5, 0.8])]):
    print L
    L = normalizeVector(L)
    print L
    I_32F = half_lambert.diffuse(N_32F, L)

    h, w, cs = N_32F.shape

    C_32F = np.zeros((h, w, cs), dtype=np.float32)
    I_32F_flat = I_32F.reshape(h * w)
    C_32F_flat = C_32F.reshape(-1, 3)

    C_32F_flat[:, :] = colors[0]

    for border, color in zip(borders, colors[1:]):
        C_32F_flat[I_32F_flat > border, :] = color

    return C_32F
Пример #10
0
def estimatePhi(N_sil, I_sil):
    num_bins = 16
    I_ids = luminanceClusters(I_sil, num_bins)

    N_centers = np.zeros((num_bins, 3))
    hist = np.zeros((num_bins))

    for ni, I_id in enumerate(I_ids):
        N_centers[I_id] += N_sil[ni]
        hist[I_id] += 1.0

    hist_positive = hist > 0.0

    N_centers[hist_positive] = normalizeVectors(N_centers[hist_positive])

    I_id_max = np.max(np.where(hist_positive))
    L = N_centers[I_id_max]
    L[2] = 0.0
    L = normalizeVector(L)
    return L
Пример #11
0
def testDiffuse(method_name, estimate_func):
    L_g = normalizeVector(np.array([-0.5, 0.7, 0.5]))
    for data_name in normal.dataNames():
        N_32F, A_8U = normal.loadData(data_name)
        I_32F, A_8U = diffuse.loadData(data_name, L_g)
        estimateResultFunc(data_name, "Lambert", N_32F, L_g, I_32F, A_8U, method_name, estimate_func)