Skip to content

How to using mask image to remove pixels from original image? #176

@sergiotapia

Description

@sergiotapia

Sorry for the "guide" type question, but having a hard time finding the right docs here. I have an original image, and using SAM2 I created a mask of the image with the pixels I am interested in keeping.

image image

In python here's what I did with the Image library, and it works, results in the image I'm looking for.

from PIL import Image

# Load the original image and the mask
original = Image.open("original.png")
mask = Image.open("mask.png").convert("L")  # Convert mask to grayscale

# Ensure both images are the same size
if original.size != mask.size:
    raise ValueError("Original and mask images must have the same dimensions")

# Create a new transparent image and paste the original using the mask
result = Image.new("RGBA", original.size)
result.paste(original, (0, 0), mask)

# Save the result
result.save("result.png")

How can I do similar with the Image library in Elixir?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions