NVIDIA / NVIDIA/nvImageCodec

Encode array with alpha channel

Open
#36 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
Jupyter Notebook
Stars
159
Forks
22
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Encoder.encode and the numpy-array-to-nvimagecodec.Image conversion path shown in the report. Reproduce the 4-channel uint8 PNG case and compare it with the CodeStream/decode path using UNCHANGED; done means the array encodes successfully to PNG with its alpha channel preserved, with coverage for the reported case.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
computer-vision
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.