Nodes/HommageTools for ComfyUI/HT Multi Mask Dilate
ComfyUI Node

HT Multi Mask Dilate

One mask, many subjects, zero manual cropping

By ArtHommage·Created 2 years ago·Updated about a year ago· 4
HT Multi Mask Dilate
  • image
  • mask
  • cropped_masks
  • cropped_images
  • widths
  • heights
  • scale_factors
  • is_multi_region
  • region_count
  • region_indices
scale_modeScale Closest
padding64
connectivity8-connected
max_regions10

You've got a mask that covers several separate things - three faces in a group photo, five product shots on a sheet, a comic page with multiple panels. Standard ComfyUI mask tools treat it as one blob. HT Multi Mask Dilate, from HommageTools, splits it into its connected regions, crops each one out of the image, and hands you the whole set as aligned batches. It's the "extract every subject at once" node.

How it works

The mechanism is textbook computer vision: it labels connected components in the mask using scipy.ndimage (so if you hit an ImportError on scipy, that's the reason - more below), finds the bounding box of each component, pads it, and crops both image and mask to that box. Then it rescales each crop toward the pack's standard buckets - 512, 768, 1024 - according to the scale_mode you pick.

The inputs that matter:

  • image and mask - the source pair. Both required, same dimensions.
  • scale_mode - Scale Closest (nearest bucket), Scale Up, Scale Down, or Scale Max (always 1024). This decides how big each cropped region ends up, which matters a lot for downstream processing like per-face refinement.
  • connectivity - 4-connected vs 8-connected. 8-connected (default) treats diagonally-touching pixels as the same region, which is usually what you want for organic subjects; 4-connected splits harder and can break one subject into pieces.
  • padding - extra border around each crop, default 64. Leave room for faces/hands to not be clipped.
  • max_regions - cap on how many regions it'll chase, default 10.

What comes out

The outputs are aligned batches, which is the nice part:

  • cropped_masks and cropped_images - the crop of every region, stacked as a batch.
  • widths, heights, scale_factors - per-region metadata.
  • is_multi_region, region_count, region_indices - flags and indices you can feed into a conditional or a switch.

That batch layout is what makes it usable: wire cropped_images into a batch-capable sampler or upscaler and process every face at once, instead of hand-plumbing a loop. Pair it with something like the pack's HT Detection Batch Processor for the full "find, crop, process, recombine" pipeline.

Installing it

Part of HommageTools. ComfyUI Manager → search HommageTools, or:

cd ComfyUI/custom_nodes
git clone https://github.com/ArtHommage/HommageTools.git
cd HommageTools && pip install -r requirements.txt

Then restart. Gotcha: the node imports scipy, but scipy is not in the pack's requirements.txt. If you get a ModuleNotFoundError: scipy when the pack loads, install it yourself:

pip install scipy

Where people get burned

  • Empty or near-empty masks produce zero components, and the node's behavior on that path is best handled by checking region_count before using the crops.
  • All crops get resized to the same bucket size, which can distort wildly different aspect ratios. If one region is tall and another wide, Scale Closest is the least surprising choice.
  • The masks and images are resized together, so they stay aligned - that's the part that makes this safe to chain into mask-guided sampling.

For batch subject extraction it saves real hours. Just remember the scipy install.

CategoryHommageTools

Inputs (6)

NameTypeDefaultDescription
imageIMAGE
maskMASK
scale_modeCOMBOScale Closest4 options: Scale Closest, Scale Up, Scale Down, Scale Max
paddingINT640–256
connectivityCOMBO8-connected2 options: 4-connected, 8-connected
max_regionsINT101–100

Outputs (8)

NameTypeDescription
cropped_masksMASK
cropped_imagesIMAGE
widthsINT
heightsINT
scale_factorsFLOAT
is_multi_regionBOOLEAN
region_countINT
region_indicesINT