HT Mask Dilate
Crop to the mask, right-size the subject, know the scale factor
- image
- mask
- dilated_mask
- cropped_image
- width
- height
- scale_factor
The name says "dilate," but the thing this node actually does is more useful: it finds where the non-zero pixels in your mask are, crops the image (and mask) to that bounding box, and resizes the crop to a standard dimension - reporting the scale factor it used. If you've got a subject isolated by a mask and you want to process it at a consistent size without the dead space around it, this is the node.
How it works
Three steps, all grounded in the source:
- Find the bounds. It scans the mask for non-zero pixels and computes the tight bounding box around them (with
padding, default 64, breathing room around the content). - Crop. Both the image and the mask get cut to that box, aligned.
- Scale to a bucket. The cropped long edge is resized to a "standard" size chosen by
scale_mode:Scale Closest(default) - nearest standard bucket to the crop size; least distortion, keeps things roughly as big as they were.Scale Up- only ever scales up to the next bucket (good for making a small subject big enough to detail properly).Scale Down- only scales down (for fast previews or model input constraints).Scale Max- scale up to the largest bucket.
Outputs: dilated_mask and cropped_image (both BHWC, ready to feed the next node), plus width, height (the final crop dimensions), and scale_factor - the float you can multiply a coordinates/width by if anything downstream needs to translate positions back to full-frame space.
What it's for
The classic use: masked subject → this node → detail/upscale pass → paste back. You detect a person, crop them out at a clean standard size, run a high-quality pass on just them, and use the scale factor to place them back correctly. It's also the "extract the subject from the background" step for layer workflows - a natural feed into the pack's Layer Collector, where the mask becomes the alpha. And because it normalizes size, it's how you make differently-sized masked subjects uniform before a batch pass.
Two inputs matter and the rest is taste: mask (the content finder) and scale_mode (what "standard size" means to you). The KB's inpainting essay covers why masking + cropping is the pattern behind most local edits - this node is that pattern's plumbing.
Installing
Standard pack install - Manager → "HommageTools for ComfyUI", or:
cd ComfyUI/custom_nodes
git clone https://github.com/ArtHommage/HommageTools.git
cd HommageTools && pip install -r requirements.txt
restart. No models, no extra dependencies.
The honest take
Solid, well-scoped utility - but mind two things. First, it handles one contiguous region per run; if your mask contains multiple separated blobs, the bounding box will span them all and include the gaps, and you'd want the pack's Multi Mask Dilate variant for region-per-blob processing. Second, it's easy to conflate "dilate" with mask expansion - this node doesn't grow your mask outward; if you want that, you want a proper morphological dilation elsewhere. And as always in this pack: alpha software, so check the scale-factor math again after an update before trusting it in a coordinate-sensitive pipeline.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| mask | MASK | — | |
| scale_mode | COMBO | Scale Closest | 4 options: Scale Closest, Scale Up, Scale Down, Scale Max |
| padding | INT | 640–256 | — |
Outputs (5)
| Name | Type | Description |
|---|---|---|
| dilated_mask | MASK | — |
| cropped_image | IMAGE | — |
| width | INT | — |
| height | INT | — |
| scale_factor | FLOAT | — |