I tried replacing a glowing cube in a sticker with a gift box while keeping the character unchanged. The part I wanted to get right was the cyan light on the hands and the edge of the gift when the PNG goes on a different background. I tested two local diffusion models, MiniMax-H3 Image and Qwen-Image 2.1 Turbo, in TensorSharp (I maintain it).
The workflow
- Start with three images: the original RGBA PNG, a clean close-up of the replacement object, and a lighting reference. Put the source first. Inspect the object reference before running: my first gift reference had fingers over the lower edges. Cleaning only that reference removed the pink notch in both models at two seeds, with the same edit mask and alpha.
- Use two masks for the matched runs. The edit mask says where pixels may change. The foreground matte says how opaque the generated foreground and glow should be in that area. MiniMax's decoder produces RGB, so a new transparent silhouette needs a supplied matte in this workflow. Qwen can also generate RGBA natively; keep the edit mask and omit the matte for that run.
- Preview the same PNG on dark and light. A pale rim may mean the matte extends beyond what the model drew. That's what happened with Qwen in my shared-matte run. Its native RGBA result lost the hard rim, but a softer halo remained. MiniMax filled the shared matte more closely with this reference, although its 512 setting made the cyan seam brighter and the bow paler.
The first figure row uses the same prompt, edit mask, foreground matte, source and references. The two model-specific options below it are labeled separately. Nothing in the outputs was retouched; the dark and light backgrounds are display composites.
Settings and timing
Apple M5 Pro (48 GB), Metal, TensorSharp f7c3ca8f. The source and output were 1254 × 1254. Both used grayscale mask mode, crop padding 64 px, and no extra feather. Reference close-ups were 384 × 384. These are local Server.Host edit times, excluding startup and transfers. Seed 0 was the first matched request; subsequent calls could reuse conditioning. One sample per setting and seed.
| Setting | Seed 0 | Seed 42 |
|---|
| MiniMax Q4_K_M, pDMD 2 steps, CFG 1, shared matte | 127.1 s | 89.6 s |
| Same MiniMax setup, reference short-edge floor 512 | 51.8 s | 43.9 s |
| Qwen Turbo Q5_K_S, fixed 8-step Euler schedule, CFG 1, shared matte | 13.3 s | 9.1 s |
| Same Qwen Turbo setup, native RGBA without an external matte | 10.9 s | 9.0 s |
MiniMax used the adapter's [1, 12/13, 0] sigma schedule and by-step heads. Qwen used its built-in Turbo sigmas. The 512 setting reduced MiniMax's conditioning rows from 3,259 to 923 without changing its sampling grid. The two models sampled at different internal sizes for this crop (2016 × 2080 vs. 320 × 320), so the table compares these workflows, not equal-resolution model speed. All tests preserved the decoded RGBA of the 1,547,143 pixels outside the edit mask.
What I'd pick: MiniMax default with the aligned matte for this final asset, and Qwen native RGBA for quick iterations. If you're trying both, keep your inputs fixed and compare the edges on dark and light before deciding.
Reproduce with your own images
On Apple silicon, install the .NET 10 SDK, CMake 3.20+, and Xcode Command Line Tools. Then build the CLI and its Metal backend (build notes):
git clone https://github.com/zhongkaifu/TensorSharp.git
cd TensorSharp
git checkout f7c3ca8f6e28a5c58e07a43cebb459130deb78e5
TENSORSHARP_GGML_GIT_REF=bb877c0c51f38c52ee2d5e41d58e3d0c20f3fed4 \
dotnet build TensorSharp.Cli/TensorSharp.Cli.csproj -c Release
Use your own PNGs. The first image is the source; the next two are the object and lighting references, in that order. The references can have their own dimensions. Make two opaque grayscale PNGs at the source's exact dimensions:
- Edit mask: white = edit, black = keep, gray = blend. Cover the object and any area where you want to change its reflection.
- Foreground matte: inside the edit region, white = opaque, black = transparent, gray = partial alpha. Draw this for the shape you want to keep, including any soft glow. The matte is separate from the edit mask.
Prompt used for the figure (replace the object and lighting descriptions for your own images):
Lighting match demo: Replace the luminous cube in Picture 1 with the blue gift and gold ribbon from Picture 2. Fit the whole gift neatly inside the original cube silhouette. Around the gift, reconstruct the original cool reflected light as a very soft, pale cyan-white glow, brightest immediately above the palms, fading smoothly into the original surrounding tones. Match the hue and brightness of that neighboring glow in Picture 1, using Picture 3 only as a color reference. No solid blue or gray background patch, no dark outline, no new halo ring. Keep the character, hands, hair, clothing and everything outside the selection unchanged. No words or additional objects.
Paste this in Bash or Zsh from the repo root after changing the five paths and the prompt. The first two runs are the matched quality comparison. The last two are optional; you can run only the last command after defining the variables and arrays if you want Qwen native RGBA without a matte. Use SEED=42 for a second run.
# Run from the TensorSharp checkout, in Bash or Zsh.
# Change these paths and the prompt to match your own images.
SOURCE="${SOURCE:-/absolute/path/to/source.png}"
REF_OBJECT="${REF_OBJECT:-/absolute/path/to/object-reference.png}"
REF_LIGHT="${REF_LIGHT:-/absolute/path/to/lighting-reference.png}"
MASK="${MASK:-/absolute/path/to/edit-mask.png}"
MATTE="${MATTE:-/absolute/path/to/foreground-matte.png}"
PROMPT="${PROMPT:-Replace the object in Picture 1 with the object from Picture 2. Use Picture 3 only as a lighting reference. Preserve everything outside the selection.}"
CLI=TensorSharp.Cli/bin/TensorSharp.Cli.dll
DOTNET="${DOTNET:-dotnet}"
OUT="${OUT:-$PWD/masked-edit-results}"
SEED="${SEED:-0}"
export TENSORSHARP_MODELS="${TENSORSHARP_MODELS:-$HOME/.cache/tensorsharp/models}"
mkdir -p "$OUT" "$TENSORSHARP_MODELS" || exit 1
common=(
--backend ggml_metal
--image "$SOURCE" --image "$REF_OBJECT" --image "$REF_LIGHT"
--prompt "$PROMPT"
--mask "$MASK" --mask-mode grayscale --mask-feather 0
--mask-crop --mask-crop-padding 64 --keep-source-size
--diffusion-seed "$SEED"
)
mini=(--config config/minimax-h3-image-q4km.json
--lora config/lora/minimax-h3-image-pdmd-2step.json)
qwen=(--config config/qwen-image-2.1-turbo.json)
matte=(--mask-foreground-matte "$MATTE")
# Matched comparison: same edit mask AND foreground matte.
"$DOTNET" "$CLI" "${common[@]}" "${mini[@]}" "${matte[@]}" \
--output "$OUT/minimax-default.png" || exit 1
"$DOTNET" "$CLI" "${common[@]}" "${qwen[@]}" "${matte[@]}" \
--output "$OUT/qwen-shared-matte.png" || exit 1
# Optional variants. Qwen generates alpha itself in the last run.
"$DOTNET" "$CLI" "${common[@]}" "${mini[@]}" "${matte[@]}" \
--reference-floor 512 --output "$OUT/minimax-floor512.png" || exit 1
"$DOTNET" "$CLI" "${common[@]}" "${qwen[@]}" \
--output "$OUT/qwen-native-rgba.png" || exit 1
Outputs go to masked-edit-results/. The configs download the required weights on first use if they're not already cached. See the MiniMax config and weights, pDMD 2-step LoRA, and Qwen Turbo config and weights. Check the model and adapter licenses separately from the runtime license.
These commands reproduce the image-editing settings. Each starts a separate CLI process, so shell wall times are not directly comparable with the warm Server.Host request times in the table.
If you do transparent inpainting locally, how are you getting clean reflected light without a halo? I'd especially like to compare notes on matte alignment and how far to extend the edit mask around the glow.