MaskToPatchMask
The tiny node that decides which patches your subject owns
- mask
- MASK
MaskToPatchMask is the single-mask version of the pack's pixel-to-patch converter, and it's the one you'll actually see inside the shipped example workflows - both chroma_chara_consist.json and qwen_chara_consist.json use it to turn SAM's subject masks into the patch-level masks the attention machinery reads. Small node, small job: take one pixel mask, average it over 16×16 blocks, keep each block if its average clears a threshold. Output is a coarse, blocky mask where each block is on or off - exactly what a patch-based attention override can consume.
The inputs that matter
mask(MASK) - your subject's pixel mask, usually straight out of GroundingDinoSAMSegment from the Segment Anything pack.patch_size(INT, default 16) - the block size. 16 matches Flux/Chroma/Qwen patch sizes, so leave it unless you know your model does otherwise.threshold(FLOAT, default 1.0) - the fraction of the block that must be foreground to keep the patch.
That default threshold is where people get burned. The node keeps a block when the mean pixel value is ≥ threshold, and 1.0 means a block must be entirely white to survive. SAM masks have soft, anti-aliased edges, so every block along the subject's boundary has pixels that are grayish - below a mean of 1.0 - and gets dropped. Result: your subject mask arrives with a shaved-off border, and the consistency locks onto a slightly-too-small subject. The fix is boring and effective: lower the threshold to 0.5 (or threshold the mask to pure black/white first). A block half-covered by the subject is still subject.
Output and wiring
One output, a MASK at patch resolution - same [B, H, W] layout, just blocky. Wire it where the batched flow expects patch masks (BatchedMaskedReferenceGen's source_patch_masks or target_patch_masks). If you'd rather convert a whole batch of masks at once with padding built in, use MasksToPatches instead; this node is for the single-mask case, which is why the examples use it per subject.
Install
ComfyUI Manager → search "Comfyui_CharaConsist", or git clone https://github.com/thatname/Comfyui_CharaConsist.git into custom_nodes, restart, find it under chara_consist. No pip deps. Flux, Chroma, and Qwen-Image models only - if your model isn't one of those, the pack's attention hooks never fire and this node is converting masks nobody will read.
One last gotcha: like all the patch converters, it truncates to whole blocks. A mask that isn't a multiple of 16 on each axis loses a partial block off the edge silently. Crop to a multiple of 16 before you convert, lower the threshold, and preview the output with MaskPreview - the blockiness is expected, but missing subject patches are a real problem hiding in plain sight.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | — | |
| patch_size | INT | 16 | — |
| threshold | FLOAT | 1.00 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MASK | MASK | — |