ImageGen soft matte erases opaque foreground pixels beyond --opaque-threshold

Open Beginner friendly
#61,432 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
80/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
ai

Research direction

The soft-matte alpha is computed in codex-rs/skills/src/assets/samples/imagegen/scripts/remove_chroma_key.py around lines 210-222, where the distance alpha and color-dominance alpha are combined with min(). Run the reproduction from the issue to confirm the alpha values for green, turquoise and red. Done means the turquoise stripe stays at alpha 255 with soft matte on, the green background is transparent, and the transparent count is 900, with a regression test for a saturated foreground outside the transition band.

Written by the indexing model from the issue text.

Description

bug imagen skills

The ImageGen skill's chroma-key helper removes an entire turquoise foreground region when keying out green. The foreground is 224 units from the key by the helper's max-channel distance. With --opaque-threshold 96, the help text says it should remain fully opaque.

Reproduction From the repository root at de83e7674a69b9ae18544dd1fbf53f31bfe8c640, on Linux x86_64 with Python 3.12.14 and Pillow 13.0.0. This creates three solid stripes so the result can be checked without visual judgment.

d=$(mktemp -d)
python3 - "$d/input.png" <<'PY'
import sys
from PIL import Image
im = Image.new("RGB", (90, 30), "#00ff00")
im.paste("#00ffe0", (30, 0, 60, 30))
im.paste("#ff0000", (60, 0, 90, 30))
im.save(sys.argv[1])
PY
python3 codex-rs/skills/src/assets/samples/imagegen/scripts/remove_chroma_key.py \
  --input "$d/input.png" --out "$d/soft.png" --key-color '#00ff00' \
  --soft-matte --opaque-threshold 96
python3 - "$d/soft.png" <<'PY'
import sys
from PIL import Image
im = Image.open(sys.argv[1])
print([im.getpixel((x, 15))[3] for x in (15, 45, 75)])
PY

Observed The alpha values for green, turquoise, and red are [0, 0, 255]. The helper reports 1800/2700 transparent pixels. With the same input and plain hard keying, the values are [0, 255, 255].

Expected With soft matte enabled, the green background is transparent and both foreground stripes stay opaque. Only 900 pixels should be transparent.

Suggested fix Enforce the upper distance threshold before applying the color-dominance adjustment. Currently the minimum of the distance and dominance alphas can be zero even after the distance calculation returned 255. A saturated foreground outside the transition band would make a regression test. Alpha calculation

Dominant language
Rust
Stars
135k
Forks
21.4k
Avg merge
1m
Merged PRs (30d)
997

Getting set up

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.

More from openai/codex

All issues in openai/codex

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.