ComfyUI Node

Mask Gen

One node that quietly replaces five mask packs

By criskb·Created 7 months ago·Updated 5 months ago· 0
Mask Gen
  • image
  • base_mask
  • mask
  • preview
  • mask_info
settings_json{"mode":"luminance","channel":"luma","threshold":0.5,"softness":0.08,"min_value":0.2,"max_value":0.8,"hue_center":120.0,"hue_width":24.0,"target_r":0.0,"target_g":1.0,"target_b":0.0,"color_tolerance":0.25,"edge_radius":1.0,"edge_strength":1.0,"center_x":0.5,"center_y":0.5,"radius":0.28,"falloff":1.0,"combine_mode":"replace","expand_pixels":0,"blur_radius":0.0,"mask_gamma":1.0,"invert_mask":false}

Most ComfyUI mask nodes are single-trick ponies: one for luma keys, one for hue, one for chroma key, one for radial gradients. x1MaskGen from MKRShift Nodes folds nine mask-building modes into one node and lets you pick the mode without swapping nodes. It's the kind of utility you install for one project and then keep wired into every graph because it's always the right tool for something.

It lives in the Utility/Mask branch, next to the pack's other mask helpers, and - unlike the big detection suites in the masking-detection-detailing knowledge doc - it's 100% deterministic pixel math. No YOLO, no SAM, no model download. It is a keyer, not a detector.

What it can build

The whole thing is driven by a mode field inside a single settings_json string. The modes, straight from the source:

  • luminance / channel - classic luma or single-channel keys (luma, red, green, blue, alpha)
  • hue / saturation / value - HSV selection, with hue_center and hue_width for hue gating
  • chroma_key - fastest route to isolating a known target color, with target_r/g/b and color_tolerance
  • skin_tones - a portrait shortcut that gets you a soft skin isolation without dialing a manual key color
  • edge - line-driven mattes for stylized comps
  • radial - a center-based falloff mask using center_x, center_y, radius, and falloff

That JSON-instead-of-widgets design is worth calling out because it's the pack's house style: power over discoverability. You edit a text blob instead of twiddling sliders, which is fine once you're comfortable, mildly annoying the first time. The author ships a custom frontend for this node (it's in the pack's WEB_DIRECTORY), so don't be surprised if the UI looks a bit fancier than the node list implies.

The inputs that matter

You feed it an image and a settings_json string. Inside that string, the fields you'll actually touch:

  • mode - which keyer runs (the list above)
  • threshold and softness - how hard the key cuts, and how much feather at the boundary
  • combine_mode - replace, multiply, maximum, minimum, or add. This is how you stack a second pass on top of a first one instead of losing it
  • expand_pixels, blur_radius, mask_gamma, invert_mask - the "finalize the shape" quartet every mask workflow ends with

There's also an optional base_mask input. Wire a mask in and the new key gets combined with it according to combine_mode, which is exactly the pattern you need for "chroma key the background, then keep it inside my subject mask."

Outputs

Three, and they're all useful:

  • mask - the MASK tensor, ready for a KSampler's denoise-mask, an Impact detailer, or a composite
  • preview - an IMAGE version so you can see the selection without adding a Preview Mask node
  • mask_info - a STRING summary of what settings actually ran

mask_info is more useful than it sounds: when you come back to a workflow three weeks later and the mask isn't what you expected, it tells you the resolved mode and settings instead of making you decode the JSON by hand.

Installing it

x1MaskGen ships in the MKRShift Nodes pack by Cris K B. Easiest path is ComfyUI Manager - search "MKRShift Nodes" and install. Manual route:

cd ComfyUI/custom_nodes
git clone https://github.com/criskb/MKRShift_Nodes

Restart ComfyUI and you're done. There's no requirements.txt to fight and nothing downloads a model - this node is plain torch/numpy. One honest caveat: the pack is enormous (Blender bridges, G-code nodes, audio tools you'll never open), so you're installing a Swiss-army knife to get one tool. It's still worth it if you'll use a few of the x1 nodes.

Where people get burned

The classic miss is typing a mode name wrong - settings_json doesn't validate against a dropdown, and an unknown mode silently falls back to luminance. Also, invert_mask defaults to false inside the JSON even if you think you toggled it, so check that field before you wonder why your subject is transparent. Keep the mode + combine_mode pair in mind: replace clobbers your base_mask, which is usually not what you want on a second pass.

CategoryMKRShift Nodes/Utility/Mask

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
settings_jsonSTRING{"mode":"luminance","channel":"luma","threshold":0.5,"softness":0.08,"min_value":0.2,"max_value":0.8,"hue_center":120.0,"hue_width":24.0,"target_r":0.0,"target_g":1.0,"target_b":0.0,"color_tolerance":0.25,"edge_radius":1.0,"edge_strength":1.0,"center_x":0.5,"center_y":0.5,"radius":0.28,"falloff":1.0,"combine_mode":"replace","expand_pixels":0,"blur_radius":0.0,"mask_gamma":1.0,"invert_mask":false}
base_maskoptMASK

Outputs (3)

NameTypeDescription
maskMASK
previewIMAGE
mask_infoSTRING