Skip to content

Support Transparent Segmentations #147

@Sharpz7

Description

@Sharpz7

https://github.com/radoss-org/retuve/blob/main/retuve/classes/draw.py#L112-L135

def apply_to_image(self, image):
    if not any(self.operations.values()):
        return image

    base = Image.fromarray(image)

    if base.mode != "RGBA":
        base = base.convert("RGBA")

    overlay = Image.new("RGBA", base.size, (0, 0, 0, 0))
    draw = ImageDraw.Draw(overlay)

    for optype in DrawTypes.ALL():
        for args, kwargs in self.operations[optype]:
            func = DrawTypes.type_to_func(draw, optype)
            func(*args, **kwargs)

    final_image = Image.alpha_composite(base, overlay)

    return np.array(final_image.convert("RGB"), dtype=np.uint8)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions