コード例 #1
0
    def _runLayer(self, layer_file):
        C0_8U = loadRGBA(layer_file)

        if C0_8U is None:
            return

        A_8U = alpha(C0_8U)

#         if A_8U is None:
#             return

        C0_32F = to32F(rgb(C0_8U))
        I_32F = luminance(C0_32F)

        Lab_32F = rgb2Lab(C0_32F)

        th_specular = 0.2
        th_contour = 0.02
        th_material = 0.1
        E_32F = DoG(I_32F, sigma=2.0)

        contour = th_contour * np.min(E_32F) - E_32F
        contour *= 1.0 / np.max(contour)
        contour = np.clip(contour, 0.0, 1.0)
        specular = E_32F - th_specular * np.max(E_32F)
        specular *= 1.0 / np.max(specular)
        specular = np.clip(specular, 0.0, 1.0)

        material = rgb(C0_8U)
#         edge_mask = np.zeros(I_32F.shape, dtype=np.uint8)
#         edge_mask[contour > 0.0] = 1.0
#         material = cv2.inpaint(material, edge_mask, 3, cv2.INPAINT_TELEA)

        for i in xrange(1):
            material = cv2.medianBlur(material, ksize=7)
#         material = th_material * np.max(np.abs(E_32F)) - np.abs(E_32F)
#         material *= 1.0 / np.max(material)
#         material = np.clip(material, 0.0, 1.0)
#         material[material > 0.0] = 1.0
        E_32F[E_32F < 0.0] = 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 = 1
        num_cols = 4
        plot_grid = SubplotGrid(num_rows, num_cols)

        plot_grid.showImage(C0_8U, r'$C$')
        #plot_grid.showImage(setAlpha(C0_32F, material), r'$Material$')
        plot_grid.showImage(setAlpha(material, A_8U), r'$Material$')
        plot_grid.showImage(setAlpha(C0_32F, contour), r'$Contour$')
        plot_grid.showImage(setAlpha(C0_32F, specular), r'$Specular$')

        showMaximize()
コード例 #2
0
def LabFeatures(image, w_L=1.0, w_a=1.0, w_b=1.0):
    img_32F = to32F(image)
    rgb_32F = img_32F[:, :, :3]
    Lab_32F = rgb2Lab(rgb_32F)

    h, w, cs = image.shape
    features = Lab_32F.reshape(h * w, -1)

    features[:, 0] *= w_L
    features[:, 1] *= w_a
    features[:, 2] *= w_b

    return features
コード例 #3
0
def LabFeatures(image, w_L=1.0, w_a=1.0, w_b=1.0):
    img_32F = to32F(image)
    rgb_32F = img_32F[:, :, :3]
    Lab_32F = rgb2Lab(rgb_32F)

    h, w, cs = image.shape
    features = Lab_32F.reshape(h * w, -1)

    features[:, 0] *= w_L
    features[:, 1] *= w_a
    features[:, 2] *= w_b

    return features
コード例 #4
0
    def _compute(self):
        C0_8U = self._image
        C0_32F = to32F(rgb(C0_8U))
        Lab_32F = rgb2Lab(C0_32F)
        I_32F = luminance(C0_32F)

        h, w = I_32F.shape[:2]
        edge_mask = np.zeros((h, w), dtype=np.uint8)

        #E_32F = DoG(Lab_32F, sigma=7.0)

        #         E_32F[E_32F > 0.0] = 0.0
        #         E_32F = - E_32F
        #         E_32F /= np.max(E_32F)
        #         th_contour = 0.05
        #         for ci in xrange(3):
        #             edge_area = E_32F[:, :, ci] > th_contour
        #             edge_mask[edge_area] = 255

        E_32F = DoG(I_32F, sigma=3.0)
        h, w = E_32F.shape[:2]
        E_norm = -np.array(E_32F)
        E_norm[E_norm < 0.0] = 0.0

        th_contour = 0.1
        edge_area = E_norm > th_contour * np.max(E_norm)
        edge_mask[edge_area] = 255
        self._edge_mask = edge_mask

        labels = np.array(edge_mask)

        mask = np.ones((h + 2, w + 2), dtype=np.uint8)
        mask[1:-1, 1:-1] = self._edge_mask

        for label in xrange(1, 3):
            regionSeeds = np.where(self._edge_mask == 0)
            if len(regionSeeds[0]) == 0:
                break
            p = (regionSeeds[1][0], regionSeeds[0][0])
            cv2.floodFill(labels, mask, p, label)
            self._edge_mask[labels == label] = label
        self._labels = labels
コード例 #5
0
    def _compute(self):
        C0_8U = self._image
        C0_32F = to32F(rgb(C0_8U))
        Lab_32F = rgb2Lab(C0_32F)
        I_32F = luminance(C0_32F)

        h, w = I_32F.shape[:2]
        edge_mask = np.zeros((h, w), dtype=np.uint8)

        # E_32F = DoG(Lab_32F, sigma=7.0)

        #         E_32F[E_32F > 0.0] = 0.0
        #         E_32F = - E_32F
        #         E_32F /= np.max(E_32F)
        #         th_contour = 0.05
        #         for ci in xrange(3):
        #             edge_area = E_32F[:, :, ci] > th_contour
        #             edge_mask[edge_area] = 255

        E_32F = DoG(I_32F, sigma=3.0)
        h, w = E_32F.shape[:2]
        E_norm = -np.array(E_32F)
        E_norm[E_norm < 0.0] = 0.0

        th_contour = 0.1
        edge_area = E_norm > th_contour * np.max(E_norm)
        edge_mask[edge_area] = 255
        self._edge_mask = edge_mask

        labels = np.array(edge_mask)

        mask = np.ones((h + 2, w + 2), dtype=np.uint8)
        mask[1:-1, 1:-1] = self._edge_mask

        for label in xrange(1, 3):
            regionSeeds = np.where(self._edge_mask == 0)
            if len(regionSeeds[0]) == 0:
                break
            p = (regionSeeds[1][0], regionSeeds[0][0])
            cv2.floodFill(labels, mask, p, label)
            self._edge_mask[labels == label] = label
        self._labels = labels