BatchImageToMask
Turn segmentation renders into the masks this pack actually needs
- images
- MASKS
ComfyUI has a core "Image To Mask" node, so why does a pack ship its own? Because that core node works on one image at a time, and this one eats whole batches and throws in a dilation pass. BatchImageToMask is the plumbing node of Pablerdo's ComfyUI-MultiCutAndDrag pack: it takes RGB images - segmentation renders, SAM outputs that landed as images, black-and-white plates - and converts them into proper binary MASK tensors that the pack's drag nodes will actually accept.
If you've ever wired a mask-looking thing into a MASK input and watched it silently misbehave, this is the node that fixes the type mismatch in one step.
How it works
Nothing fancy, and that's the point. For each image in the batch it converts to grayscale by averaging the color channels, then applies your threshold (a 0–1 float): anything above it becomes 1.0, everything else 0.0. The result is a clean binary mask, batched, same device as your input.
The node also does defensive shape handling - it sniffs for [B, H, W, C] vs [B, C, H, W] layouts and transposes if needed. It prints a running commentary about shapes to your console while it works, which is noisy but harmless; it's just the author's debugging prints left in.
If you raise dilation_amount above its default of 0, each mask gets run through scipy.ndimage grey dilation with a plus-shaped kernel, repeated that many times. Each pass grows the mask by about a pixel. That's the difference-maker for cut-and-drag work: a thin or anti-aliased segmentation edge gives a scrappy cut, while a dilated mask gives the cut region a bit of halo so the composite doesn't show a hard 1px seam.
Inputs and outputs
Three inputs, one output, nothing to memorize:
images- your IMAGE tensor, single or batched.threshold(float, default 0.5, range 0–1) - the grayscale cutoff for mask generation.dilation_amount(int, default 0, range 0–100) - how many times to grow the mask.
Output is a single MASKS tensor you feed straight into MultiCutAndDragOnPath's masks input, or use anywhere else a MASK is expected.
Installation
It ships with ComfyUI-MultiCutAndDrag, so:
cd ComfyUI/custom_nodes
git clone https://github.com/Pablerdo/ComfyUI-MultiCutAndDrag
then restart ComfyUI - or just install "MultiCutAndDrag" from ComfyUI Manager. Dependencies are the pack's usual set (torch, numpy, Pillow, scipy, opencv-python); there's no model download and nothing GPU-heavy beyond what you already run.
Common issues
- Threshold fights anti-aliased edges. Segmentation renders with soft edges want a lower threshold than 0.5, or you'll shave off a pixel ring of the object. For hard-edged renders, 0.5 is fine.
- Dilation is a max-filter, not a flood-fill. It rounds off detail corners a touch and only grows the mask - use a low
dilation_amount(1–3) unless you intentionally want a fat halo. - The console spam (shape prints per call) is cosmetic; if it bothers you, know it's expected behavior, not a warning.
For a small utility node it's refreshingly predictable. Batch in segmentation images, threshold, optionally inflate, and the masks come out exactly where you'd expect them.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| images | IMAGE | — | |
| threshold | FLOAT | 0.500–1 | — |
| dilation_amount | INT | 00–100 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MASKS | MASK | — |