Пример #1
0
    def _optimize(self):
        I_32F = self._I0_32F
        h, w = I_32F.shape[:2]
        I = I_32F.reshape(h * w)

        L = self._L
        N0_32F = self._N0_32F
        N0 = N0_32F.reshape(-1, 3)

        NL = np.clip(np.dot(N0, L), 0.0, 1.0)

        I = self._estimateBrightness()

        I_32F = I.reshape(h, w)

        N = np.array(N0_32F)

        A_8U = self._A_8U

        constraints = []
        w_lap = self._w_lap
        constraints.append(image_constraints.laplacianConstraints(w_c=w_lap))
        constraints.append(image_constraints.brightnessConstraints(L, I_32F, w_c=1.0))
        constraints.append(image_constraints.gradientConstraints(L, I_32F, w_c=0.5))

        w_sil = 0.2 * w_lap
        constraints.append(image_constraints.silhouetteConstraints(A_8U, w_c=w_sil))

        solver_iter = image_solver.solveIterator(constraints,
                                                 [image_constraints.postNormalize(th=0.0)])
        N = image_solver.solveMG(np.float64(N), solver_iter, iterations=self._iterations)

        self._N_32F = N.reshape(h, w, 3)
Пример #2
0
    def _interpolateNormalImage(self, N0_32F, W_32F, A_8U):
        constraints = []
        constraints.append(image_constraints.laplacianConstraints(w_c=0.1))
        constraints.append(image_constraints.normalConstraints(W_32F, N0_32F, w_c=3.0))
        L = normalizeVector(np.array([-0.2, 0.3, 0.7]))
        I_32F = luminance(to32F(rgb(self._image)))
        I_min, I_max = np.min(I_32F), np.max(I_32F)

        I_32F = (I_32F - I_min) / (I_max - I_min)

        # constraints.append(image_constraints.brightnessConstraints(L, I_32F, w_c=0.5))
        constraints.append(image_constraints.silhouetteConstraints(A_8U, w_c=0.8))

        solver_iter = image_solver.solveIterator(constraints,
                                                 [postNormalize(th=0.0)])

        N_32F = np.array(N0_32F)
        N_32F = image_solver.solveMG(N_32F, solver_iter, iterations=10)
        N_32F = image_constraints.NxyToNz(N_32F)

        return N_32F
Пример #3
0
    def _optimize(self):
        I_32F = self._I0_32F
        h, w = I_32F.shape[:2]
        I = I_32F.reshape(h * w)

        L = self._L
        N0_32F = self._N0_32F
        N0 = N0_32F.reshape(-1, 3)

        NL = np.clip(np.dot(N0, L), 0.0, 1.0)

        I = self._estimateBrightness()

        I_32F = I.reshape(h, w)

        N = np.array(N0_32F)

        A_8U = self._A_8U

        constraints = []
        w_lap = self._w_lap
        constraints.append(image_constraints.laplacianConstraints(w_c=w_lap))
        constraints.append(
            image_constraints.brightnessConstraints(L, I_32F, w_c=1.0))
        constraints.append(
            image_constraints.gradientConstraints(L, I_32F, w_c=0.5))

        w_sil = 0.2 * w_lap
        constraints.append(
            image_constraints.silhouetteConstraints(A_8U, w_c=w_sil))

        solver_iter = image_solver.solveIterator(
            constraints, [image_constraints.postNormalize(th=0.0)])
        N = image_solver.solveMG(np.float64(N),
                                 solver_iter,
                                 iterations=self._iterations)

        self._N_32F = N.reshape(h, w, 3)
Пример #4
0
    def _optimize(self):
        L = self._L
        N0_32F = self._N0_32F
        C0_32F = self._C0_32F

        LdN = LdotN(L, N0_32F)

        A_8U = self._A_8U
        layer_area = A_8U > 0.5 * np.max(A_8U)
        Cs = C0_32F[layer_area].reshape(-1, 3)
        Is = LdN[layer_area].flatten()

        M = ColorMapEstimation(Cs, Is)

        self._Cini_32F = M.shading(LdN.flatten()).reshape(self._C0_32F.shape)

        I_recovered = M.illumination(Cs)
        I_32F = np.zeros(LdN.shape)
        I_32F[:] = np.min(I_recovered)
        I_32F[layer_area] = I_recovered

        I_dog = DoG(I_32F, sigma=2.0)
        sigma = 2.0
        I_32F = np.float32(cv2.GaussianBlur(I_32F, (0, 0), sigma))
        I_lap = -cv2.Laplacian(np.float32(I_32F), cv2.CV_32F, ksize=1)

        I_lap = np.abs(I_lap)

        I_lap_median = np.median(I_lap[layer_area])
        print "I_lap_mean", np.mean(I_lap[layer_area])
        print "I_lap_median", np.median(I_lap[layer_area])

        sigma = 0.05
        epsilon = 0.0 * I_lap_median
        w_min = 0.05
        w_max = 1.0

        W_32F = w_min + (w_max - w_min) * (1.0 - np.exp(- (I_lap - epsilon) ** 2 / (sigma ** 2)))
        W_32F = w_min * np.ones(I_32F.shape[:2])
        W_32F[I_lap < epsilon] = w_min
        W_32F[I_lap > epsilon] = w_max

        W_32F[:, :] = 1.0

        constraints = []
        #W_32F = np.ones(N0_32F.shape[:2])
        #constraints.append(image_constraints.normalConstraints(W_32F, N0_32F, w_c=0.05))

        w_lap = self._w_lap
        constraints.append(image_constraints.laplacianConstraints(w_c=w_lap))
        constraints.append(image_constraints.brightnessConstraints(L, I_32F, w_c=1.0))
        constraints.append(image_constraints.gradientConstraints(L, I_32F, w_c=0.2))

        w_sil = 0.4 * w_lap
        constraints.append(image_constraints.silhouetteConstraints(A_8U, w_c=w_sil))

        N_32F = np.array(N0_32F, dtype=np.float64)

        solver_iter = image_solver.solveIterator(constraints,
                                                [image_constraints.postNormalize(th=0.0)])
                                                #[image_constraints.postComputeNz()])
        N_32F = image_solver.solveMG(N_32F, solver_iter, iterations=self._iterations)

        self._N_32F = N_32F

        LdN = LdotN(L, N_32F)

        I_32F[layer_area] = LdN[layer_area]

        self._C_32F = M.shading(I_32F.flatten()).reshape(self._C0_32F.shape)
        self._M = M