Exemplo n.º 1
0
    def _colorize_objects_for_semantic_segmentation(self, objects):
        """ Sets the color of each object according to their category_id.

        :param objects: A list of objects.
        :return: The num_splits_per_dimension of the spanned color space, the color map
        """
        if "num_labels" not in bpy.context.scene:
            raise Exception(
                "The scene is missing the custom property 'num_labels'. For generating semantic segmentation maps, this needs to contain the total number classes!"
            )

        colors, num_splits_per_dimension = Utility.generate_equidistant_values(
            bpy.context.scene["num_labels"] + 1,
            self.render_colorspace_size_per_dimension)

        for obj in objects:
            if "category_id" not in obj:
                raise Exception("The object " + obj.name +
                                " does not have a category_id.")

            self._colorize_object(obj, colors[obj["category_id"]])

        # Set world background label
        if "category_id" not in bpy.context.scene.world:
            raise Exception(
                "The world does not have a category_id. It will be used to set the label of the world background."
            )
        self._set_world_background_color(
            colors[bpy.context.scene.world["category_id"]])

        # As we don't need any color map when doing semantic segmenation, just return None instead.
        return colors, num_splits_per_dimension, None
Exemplo n.º 2
0
    def _colorize_objects_for_instance_segmentation(
            objects, use_alpha_channel, render_colorspace_size_per_dimension):
        """ Sets a different color to each object.

        :param objects: A list of objects.
        :param use_alpha_channel: If true, the alpha channel stored in .png textures is used.
        :param render_colorspace_size_per_dimension: The limit of the colorspace to use per dimension for generating colors.
        :return: The num_splits_per_dimension of the spanned color space, the color map
        """
        # + 1 for the background
        colors, num_splits_per_dimension = Utility.generate_equidistant_values(
            len(objects) + 1, render_colorspace_size_per_dimension)
        # this list maps ids in the image back to the objects
        color_map = []

        # Set world background label, which is always label zero
        SegMapRendererUtility._set_world_background_color(colors[0])
        color_map.append(
            bpy.context.scene.world
        )  # add the world background as an object to this list

        for idx, obj in enumerate(objects):
            SegMapRendererUtility._colorize_object(obj, colors[idx + 1],
                                                   use_alpha_channel)
            color_map.append(obj)

        return colors, num_splits_per_dimension, color_map
Exemplo n.º 3
0
    def _colorize_objects_for_instance_segmentation(self, objects):
        """ Sets a different color to each object.

        :param objects: A list of objects.
        :return: The num_splits_per_dimension of the spanned color space, the color map
        """
        colors, num_splits_per_dimension = Utility.generate_equidistant_values(
            len(objects) + 1, self.render_colorspace_size_per_dimension)

        color_map = []

        # Set world background label
        self._set_world_background_color(colors[0])
        color_map.append({'objname': "background", 'class': -1, 'idx': 0})

        for idx, obj in enumerate(objects):
            self._colorize_object(obj, colors[idx + 1])

            obj_class = obj["category_id"] if "category_id" in obj else None
            color_map.append({
                'objname': obj.name,
                'class': obj_class,
                'idx': idx + 1
            })

        return colors, num_splits_per_dimension, color_map
Exemplo n.º 4
0
    def _colorize_objects_for_instance_segmentation(self, objects):
        """ Sets a different color to each object.

        :param objects: A list of objects.
        :return: The num_splits_per_dimension of the spanned color space, the color map
        """
        # + 1 for the background
        colors, num_splits_per_dimension = Utility.generate_equidistant_values(len(objects) + 1,
                                                                               self.render_colorspace_size_per_dimension)
        # this list maps ids in the image back to the objects
        color_map = []

        # Set world background label, which is always label zero
        self._set_world_background_color(colors[0])
        color_map.append(bpy.context.scene.world)  # add the world background as an object to this list

        for idx, obj in enumerate(objects):
            self._colorize_object(obj, colors[idx + 1])
            color_map.append(obj)

        return colors, num_splits_per_dimension, color_map