Rhynio
AI & design

ComfyUI mask is black or reversed?

A white shape on black can be fully opaque, so it can produce an empty alpha-derived mask. Compare colour and transparency separately, then choose the loading route that matches your saved PNG.

Check which channel contains the shape

Core Load Image derives MASK from inverse alpha, not visible brightness. Opaque pixels give zero; transparent pixels give one. For a painted black-and-white mask, extract a colour channel instead. Check the actual MASK output before changing prompts or models.

This follows the ComfyUI developer documentation and the inspected core loader source. Custom loaders may differ.

Same RGB shape, four different alpha patterns

In every case, stored R, G and B are 255 in the square centre and 0 outside. Only alpha changes. These are synthetic channel diagrams, not PNG decodes, ComfyUI screenshots or generated results. RGB is shown separately from transparency; an editor may discard hidden RGB when saving.

Try predicting each mask before reading its answer. The alpha panel shows opacity as grayscale, not a checkerboard. White means 1 and black means 0 in every panel. “Selected” below means high mask values; what a downstream node does with them must be checked in that workflow.

1. Opaque white centre

RGB / red mask
Alpha (opacity)
Inverse-alpha mask
Centre and outside values for case 1
RegionRedAlpha byte1 − alpha/255
Centre12550
Outside02550

Answer: Inverse alpha is zero everywhere. The red-channel route selects the white centre; the alpha route has no high-valued region.

2. Transparent centre

RGB / red mask
Alpha (opacity)
Inverse-alpha mask
Centre and outside values for case 2
RegionRedAlpha byte1 − alpha/255
Centre101
Outside02550

Answer: Inverse alpha is one in the centre and zero outside. Both routes have the same high-valued centre, for different reasons.

3. Transparent outside

RGB / red mask
Alpha (opacity)
Inverse-alpha mask
Centre and outside values for case 3
RegionRedAlpha byte1 − alpha/255
Centre12550
Outside001

Answer: Inverse alpha is zero in the centre and one outside. The red-channel route selects the centre; the alpha route selects the outside.

4. Partly transparent centre

RGB / red mask
Alpha (opacity)
Inverse-alpha mask
Centre and outside values for case 4
RegionRedAlpha byte1 − alpha/255
Centre11280.498
Outside02550

Answer: Inverse alpha is 127/255 (about 0.498) in the centre and zero outside. The red-channel centre stays one. A gray mask is not a universal edit percentage.

The equations use normalized values: colour mask = chosen colour byte / 255; alpha-derived mask = 1 − alpha byte / 255. Partial alpha is intermediate masking data, not a promise of a particular amount of visual change.

Choose one of two core loading routes

Painted black-and-white shape
Use Load Image (as Mask) (LoadImageMask) with red. For neutral grayscale, red, green and blue match. For coloured art they differ; select deliberately. Alternatively, connect Load Image’s IMAGE to Convert Image to Mask (ImageToMask), choosing red.
Shape encoded in transparency
Use Load Image (LoadImage) → MASK, or Load Image (as Mask) with alpha. That loader’s alpha option also gives inverse alpha. Transparent regions therefore become high mask values.

These routes are checked against LoadImage and LoadImageMask and ImageToMask and mask operations. Display names can change. Choose red for the IMAGE conversion route above; do not assume the IMAGE output carries the original alpha channel.

Check the mask inside your workflow

  1. Identify the loader and version. Record the core revision or release, frontend version and any custom node package. Reopen the exact saved file; a painted checkerboard is colour data, not proof of transparency.
  2. Inspect MASK directly. Connect it to core Preview Mask (MaskPreview), or Convert Mask to Image then Preview Image. An IMAGE preview alone does not establish mask polarity.
  3. Match the representation. Use colour extraction for painted brightness or inverse alpha for transparency. No-alpha images can produce a blank fallback mask with dimensions different from the image; inspect dimensions as well as values.
  4. Check polarity once. If the intended region is the opposite of the verified mask, try core Invert Mask, then preview again. Inverting an empty mask makes it full; it cannot recover a painted shape that was never extracted.
  5. If the mask looks correct, follow the connection. Check which downstream socket receives it, resizing, cropping and node-specific conventions. If loaded values disagree with a simple known file, retain that file and version details for a reproducible decoder or frontend report.

A correct preview verifies a representation at that point in the graph. It does not guarantee unchanged unmasked pixels or a particular generated result. This page does not diagnose every black preview as a bug, test models, or cover all custom loaders.

Source and version notes

Updated . AI inspected the developer documentation and core revision c5751c81abe131202eea9e4c66d000589013dd0b. The source includes a no-alpha zero-mask fallback with 64 × 64 spatial dimensions. The examples here test arithmetic only; no running ComfyUI, image editor or model was tested.

Issue #2539 records an earlier polarity misunderstanding, not proof of an outstanding defect. Use your installed version’s behavior when diagnosing a different result. Recheck the core loaders and mask operations after updates.