Skip to content

Encode array with alpha channel #36

@phatngy

Description

@phatngy

Describe the question.

I have a numpy array with alpha channel and want to use nvimagecodec to encode it. But it doesn't seem to support it and returns None.

encoder = nvimgcodec.Encoder()
arr = np.random.randint(0, 255, (1024, 1024, 4), dtype=np.uint8)
enc_bytes = encoder.encode(arr, "png")

I see nvimagecodec can transcode a PNG image with alpha channel.

decoder = nvimgcodec.Decoder()
png = nvimgcodec.CodeStream("image.png") // image with alpha channel
img_d = decoder.decode(png, nvimgcodec.DecodeParams(color_spec=nvimgcodec.ColorSpec.UNCHANGED))
enc_bytes = encoder.encode(img_d, "png")

So I tried to convert numpy array to nvimagecodec.Image and got this error:
RuntimeError: Unexpected number of channels. Only 3 channels for RGB or 1 channel for gray scale are accepted.

Check for duplicates

  • I have searched the open bugs/issues and have found no duplicates for this bug report

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions