[GH-ISSUE #7962] [Issue]: 2D Avatars: fixed colour threshold in blink/talk compositing fails dark-skinned talk pictures and leaves the open eye showing in blinks #4371

Closed
opened 2026-10-22 04:06:07 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @surrealle on GitHub (Oct 21, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/7962

Originally assigned to: @SpicyMarinara on GitHub.

Summary

The blink/talk compositor (keepAvatarFaceChange in services/avatars/generation/variant-composite.js) uses a fixed colour difference, CHANGE_THRESHOLD = 48 on the largest RGB channel, both to detect the edit and to decide which pixels to copy. That causes two bugs, depending on the character's colours:

  1. Dark skin: a clearly open mouth isn't detected, so talk pictures fail with "The image model didn't open the mouth in this picture. Try again."
  2. Pale skin with light eyes: blinks pass, but the original open iris stays visible under the closed lid, because the iris pixels count as "unchanged" and are kept from the face.

Expected behavior

  • A talk picture whose mouth is visibly open is accepted, whatever the character's skin tone.
  • A blink picture whose eyes are fully closed produces a fully closed eye in the saved picture.

Actual behavior

Talk pictures, dark-skinned character (skin ≈ rgb 86,64,88):

  • About 20 of 21 talk attempts failed with "didn't open the mouth".
  • 7 of 8 blink attempts for the same character passed.
  • Image connection: ChatGPT (Codex login), gpt-image-2.

Blinks, pale character with amber eyes (skin ≈ 243,193,180, iris ≈ 254,208,149):

  • Every saved blink shows a strip of the original amber iris under the lash line, so the eye looks half-open.
  • This happened with ChatGPT gpt-image-2 and with NanoGPT nano-banana-2.

Reproduced without any image model, by calling keepAvatarFaceChange(face, picture, variant) directly in the container on the saved 313×313 neutral-base.png faces, with hand-painted edits:

Face Painted edit Variant Result
Dark skin Open mouth, maroon interior (80,28,40) mouth-open FAIL "didn't open the mouth"
Same face, lightened (gamma 0.25, skin ≈ 194,180,194) Same maroon mouth mouth-open PASS
Dark skin Open mouth with a white teeth row mouth-open PASS
Dark skin Near-black mouth (15,5,12) mouth-open PASS
Pale skin, amber eyes Both eyes fully covered with skin-coloured lids plus a dark lash line eyes-closed PASS, but the returned picture still shows most of the original iris and loses part of the lash line
Pale skin, amber eyes Same, with a darker shaded lid (212,150,140) eyes-closed PASS, the original iris still shows through

The same mouth edit passes or fails depending only on skin tone. A blink fails to apply even when the input picture is a perfect closed eye.

Cause, from reading the code:

  • A pixel is "changed" only if its largest channel differs by ≥ 48 from every pixel within reach.
  • The main cluster must average ≥ 64.
  • Inside the chosen ellipse, only the changed pixels (dilated and feathered) are taken from the model's picture; every other pixel keeps the face's own value.

A maroon mouth on dark purple skin differs by about 45–55, so it is not detected. A light amber iris differs from a pale eyelid by less than 48, so it is treated as unchanged and copied back from the open-eyed face.

Steps to reproduce

  1. Use a character whose face sprite has dark skin (or pale skin with light-coloured eyes).
  2. In 2D Avatars → Blink and talk pictures, select Make for the talk picture (dark skin) or the blink picture (light eyes).
  3. Dark skin: the talk picture almost always fails with "didn't open the mouth". Light eyes: keep a blink and compare it with the face; the original iris is still visible under the lid.

Model-independent repro: inside the container, import keepAvatarFaceChange from /app/packages/server/dist/services/avatars/generation/variant-composite.js. Pass the saved neutral-base.png as raw RGBA {data, width, height}, plus a copy of it with an open mouth or closed eyes painted on, and the variant "mouth-open" or "eyes-closed". Check whether it throws, and look at the returned picture.

Environment

  • Marinara Engine version: 2.5.1
  • Install type: docker
  • OS + version: Ubuntu 26.04 (host)
  • Browser or app shell: BROWSER (Firefox)

Logs, screenshots, or video

Server log for a failing talk picture (repeated about 20 times for the same character):

"route":"/api/avatar-generation/pngtuber-variants","res":{"statusCode":502}
"msg":"... The image model didn't open the mouth in this picture. Try again."

Attached:

  • lillith-mouth-test.png: the three painted mouths on the dark-skinned face: maroon (FAIL), white teeth (PASS), and the same maroon mouth on the lightened face (PASS).
  • elara-saved-blinks.jpg: the open face, then two saved blinks from two image models, each with an amber iris strip under the lid.
  • elara-compositor-test.jpg: the open face, then a perfectly closed eye painted by hand, then what keepAvatarFaceChange returns for it (the iris shows through).

Additional context

Suggested direction:

  • Detection: make the threshold relative to the face's local contrast, or use a perceptual difference such as CIE Lab ΔE, so that dark skin and low-contrast palettes are not penalised.
  • Compositing: use the threshold only to find the region, then take the whole aligned region inside the ellipse from the model's picture (feathered at the edge), instead of only the pixels above the threshold.

Workaround today: for dark skin, asking the model for a row of bright white teeth gets talk pictures through. There is no prompt workaround for the blink ghosting.

Related, but not the same: #7840 (white outlines/bottom stripe), #7681.

Template check

  • I DID NOT read this template and provide the requested details.
Image Image Image
Originally created by @surrealle on GitHub (Oct 21, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/7962 Originally assigned to: @SpicyMarinara on GitHub. ## Summary The blink/talk compositor (`keepAvatarFaceChange` in `services/avatars/generation/variant-composite.js`) uses a fixed colour difference, `CHANGE_THRESHOLD = 48` on the largest RGB channel, both to detect the edit and to decide which pixels to copy. That causes two bugs, depending on the character's colours: 1. Dark skin: a clearly open mouth isn't detected, so talk pictures fail with "The image model didn't open the mouth in this picture. Try again." 2. Pale skin with light eyes: blinks pass, but the original open iris stays visible under the closed lid, because the iris pixels count as "unchanged" and are kept from the face. ## Expected behavior - A talk picture whose mouth is visibly open is accepted, whatever the character's skin tone. - A blink picture whose eyes are fully closed produces a fully closed eye in the saved picture. ## Actual behavior **Talk pictures, dark-skinned character (skin ≈ rgb 86,64,88):** - About 20 of 21 talk attempts failed with "didn't open the mouth". - 7 of 8 blink attempts for the same character passed. - Image connection: ChatGPT (Codex login), gpt-image-2. **Blinks, pale character with amber eyes (skin ≈ 243,193,180, iris ≈ 254,208,149):** - Every saved blink shows a strip of the original amber iris under the lash line, so the eye looks half-open. - This happened with ChatGPT gpt-image-2 and with NanoGPT nano-banana-2. **Reproduced without any image model,** by calling `keepAvatarFaceChange(face, picture, variant)` directly in the container on the saved 313×313 `neutral-base.png` faces, with hand-painted edits: | Face | Painted edit | Variant | Result | |---|---|---|---| | Dark skin | Open mouth, maroon interior (80,28,40) | mouth-open | FAIL "didn't open the mouth" | | Same face, lightened (gamma 0.25, skin ≈ 194,180,194) | Same maroon mouth | mouth-open | PASS | | Dark skin | Open mouth with a white teeth row | mouth-open | PASS | | Dark skin | Near-black mouth (15,5,12) | mouth-open | PASS | | Pale skin, amber eyes | Both eyes fully covered with skin-coloured lids plus a dark lash line | eyes-closed | PASS, but the returned picture still shows most of the original iris and loses part of the lash line | | Pale skin, amber eyes | Same, with a darker shaded lid (212,150,140) | eyes-closed | PASS, the original iris still shows through | The same mouth edit passes or fails depending only on skin tone. A blink fails to apply even when the input picture is a perfect closed eye. **Cause, from reading the code:** - A pixel is "changed" only if its largest channel differs by ≥ 48 from every pixel within `reach`. - The main cluster must average ≥ 64. - Inside the chosen ellipse, only the changed pixels (dilated and feathered) are taken from the model's picture; every other pixel keeps the face's own value. A maroon mouth on dark purple skin differs by about 45–55, so it is not detected. A light amber iris differs from a pale eyelid by less than 48, so it is treated as unchanged and copied back from the open-eyed face. ## Steps to reproduce 1. Use a character whose face sprite has dark skin (or pale skin with light-coloured eyes). 2. In 2D Avatars → Blink and talk pictures, select **Make** for the talk picture (dark skin) or the blink picture (light eyes). 3. Dark skin: the talk picture almost always fails with "didn't open the mouth". Light eyes: keep a blink and compare it with the face; the original iris is still visible under the lid. Model-independent repro: inside the container, import `keepAvatarFaceChange` from `/app/packages/server/dist/services/avatars/generation/variant-composite.js`. Pass the saved `neutral-base.png` as raw RGBA `{data, width, height}`, plus a copy of it with an open mouth or closed eyes painted on, and the variant `"mouth-open"` or `"eyes-closed"`. Check whether it throws, and look at the returned `picture`. ## Environment - Marinara Engine version: 2.5.1 - Install type: docker - OS + version: Ubuntu 26.04 (host) - Browser or app shell: BROWSER (Firefox) ## Logs, screenshots, or video Server log for a failing talk picture (repeated about 20 times for the same character): ``` "route":"/api/avatar-generation/pngtuber-variants","res":{"statusCode":502} "msg":"... The image model didn't open the mouth in this picture. Try again." ``` Attached: - `lillith-mouth-test.png`: the three painted mouths on the dark-skinned face: maroon (FAIL), white teeth (PASS), and the same maroon mouth on the lightened face (PASS). - `elara-saved-blinks.jpg`: the open face, then two saved blinks from two image models, each with an amber iris strip under the lid. - `elara-compositor-test.jpg`: the open face, then a perfectly closed eye painted by hand, then what `keepAvatarFaceChange` returns for it (the iris shows through). ## Additional context Suggested direction: - **Detection:** make the threshold relative to the face's local contrast, or use a perceptual difference such as CIE Lab ΔE, so that dark skin and low-contrast palettes are not penalised. - **Compositing:** use the threshold only to find the region, then take the whole aligned region inside the ellipse from the model's picture (feathered at the edge), instead of only the pixels above the threshold. Workaround today: for dark skin, asking the model for a row of bright white teeth gets talk pictures through. There is no prompt workaround for the blink ghosting. Related, but not the same: #7840 (white outlines/bottom stripe), #7681. ## Template check - [ ] I DID NOT read this template and provide the requested details. <img width="864" height="138" alt="Image" src="https://github.com/user-attachments/assets/36d7ceef-6b91-4145-950a-d7aab1409d77" /> <img width="864" height="138" alt="Image" src="https://github.com/user-attachments/assets/3336faea-056b-4abc-8e7f-cc6a53667e7e" /> <img width="900" height="270" alt="Image" src="https://github.com/user-attachments/assets/85510a09-44fa-4cd2-acae-6fd36cd5d4f2" />
bsakaguchi 2026-10-22 04:06:07 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (Oct 21, 2026):

Maintainer update: Claude is handling this issue. Codex has stopped its initial investigation; no implementation changes, commits or PR were created. Ownership remains with Claude.

<!-- gh-comment-id:6316056487 --> @SpicyMarinara commented on GitHub (Oct 21, 2026): Maintainer update: Claude is handling this issue. Codex has stopped its initial investigation; no implementation changes, commits or PR were created. Ownership remains with Claude.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#4371
No description provided.