2.6 KiB
2.6 KiB
StitchByMask
Overview
StitchByMask composites two RGB images using a soft mask, with optional mask inversion, bypass blending, feathering, and enforced output dimensions. It is geared toward portrait editing workflows where foreground/background swaps or stitched passes need precise control.
Inputs
image_a(IMAGE): Base layer tensor.image_b(IMAGE): Layer to composite overimage_a.mask(MASK, defaultNone): Blend mask. Required unlessbypass_maskisTrue. Accepted in common mask layouts ([B,H,W],[B,H,W,1],[H,W],[H,W,1]).invert_mask(BOOLEAN, defaultFalse): Flips the mask before blending.bypass_mask(BOOLEAN, defaultFalse): When enabled, ignores the supplied mask and uses a constant opacity value.opacity(FLOAT, default1.0): Global blend strength (0 preservesimage_a, 1 favoursimage_b). Applied after optional inversion.feather_radius(INT, default5): Radius (in pixels) for disk dilation before Gaussian feathering. Set to0to disable feathering.force_size(BOOLEAN, defaultFalse): IfTrue, both images (and the mask) are resized totarget_width×target_heightbefore blending.target_width(INT, default1344): Width used whenforce_sizeisTrue.target_height(INT, default768): Height used whenforce_sizeisTrue.
Outputs
stitched(IMAGE): Composited RGB image, clamped to[0, 1].processed_mask(MASK): The mask actually used for blending (after inversion, opacity scaling, feathering, and resizing).
Processing Notes
- Input tensors are converted to BHWC float32 arrays. Alpha channels, if present, are truncated to RGB.
- When
force_sizeis enabled, image tensors are resized with bilinear sampling and masks with nearest-neighbour sampling to avoid edge blurring before feathering. - Feathering expands the binary core of the mask via convolution with a disk kernel, then applies a Gaussian blur (
sigma ≈ radius/2) and takes the element-wise maximum with the original mask to avoid revealing previously masked pixels. - In bypass mode the node builds a uniform mask at the requested
opacity, allowing linear interpolation betweenimage_aandimage_bwithout supplying a mask.
Tips
- Set
feather_radiusto0when blending masks that already contain feathered edges. - Use bypass mode to create simple crossfades or to output the second pass at reduced opacity without worrying about masks.
- When enforcing a specific resolution (e.g., 1344×768 for Flux), ensure both inputs already match the target aspect to avoid distortion.*** End Patch