Skip to content

slicing and re-combining channels with alpha/matte #421

@mluerig

Description

@mluerig

I am trying to extract specific color channels from an RGBA pngs, and re-combine them so they contain only that channel-specific information + the alpha/matte layer. After a lot of trial and error (the documentation unfortunately wasn't specific on how to handle RGBA with image_combine), I finally came up with this solution:

frink <- image_read("https://jeroen.github.io/images/frink.png")
r  <- magick::image_channel(frink, "red")
a  <- magick::image_channel(frink, "alpha")
rrra_data = image_data(c(r,r,r,a), channels="rgba")
image_read(rrra_data) 

I'm sure there is a simpler solution without going through image_data/image_read?

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