KJNodes/maskinggenerated

Resize Mask(ResizeMask)

This node technically processes the input mask tensor through the `common_upscale` function, supporting batch processing.

Resize Mask

mask
mask
width
height
width
INT
height
INT
keep_proportions
upscale_method
COMBO
crop
COMBO
KJNodes

The Resize Mask node technically processes the input mask tensor through the common_upscale function and supports batch processing.

The Resize Mask node is a tool for adjusting mask dimensions. Its core function is to receive one or more masks (MASK) and scale them to specified width and height. This node provides various scaling methods and options to meet different image processing needs.

Node Functionality

This node technically processes the input mask tensor through the common_upscale function and supports batch processing. It offers multiple upsampling methods, including "nearest-exact", "bilinear", "area", "bicubic", and "lanczos", to accommodate different quality requirements. When the "Keep Proportions" option is enabled, the node automatically calculates the scaling ratio to ensure the original aspect ratio of the mask is not distorted.

Node Parameter Description - Resize Mask

Connection Inputs (Inputs)

Parameter NameData TypeRequiredDefault ValueRange/OptionsDescription
maskMASKYes--mask (Output Parameter): Outputs the resized mask.
upscale_methodCOMBOYes-"nearest-exact", "bilinear", "area", "bicubic", "lanczos"upscale_method (Input Parameter): The method used for upscaling. Options are "nearest-exact", "bilinear", "area", "bicubic", and "lanczos".

Control Parameters (Parameters)

Parameter NameData TypeRequiredDefault ValueRange/OptionsDescription
cropCOMBOYesdisabled"disabled", "center"crop (Input Parameter): Selects the cropping mode. Options are "disabled" (no cropping) or "center" (center crop), which only takes effect if the scaled dimensions exceed the target dimensions.
widthINTYes5120 - MAX_RESOLUTION (Step: 1)width (Input Parameter): The target width for the resized mask.
heightINTYes5120 - MAX_RESOLUTION (Step: 1)height (Input Parameter): The target height for the resized mask.
keep_proportionsBOOLEANYesFalse-keep_proportions (Input Parameter): Whether to maintain the original aspect ratio of the mask. When enabled, scaling is performed proportionally based on the minimum scaling ratio of width and height.

Output

Parameter NameData TypeDescription
maskMASKmask (Output Parameter): Outputs the resized mask.
widthINTwidth (Output Parameter): Outputs the actual width value of the processed mask.
heightINTheight (Output Parameter): Outputs the actual height value of the processed mask.

Usage Scenarios

In a typical image inpainting or compositing workflow, this node can be used when the size of the original image's mask does not match the target canvas. For example, before extracting a person from one image and placing them onto a new background, this node can be used to adjust the person's mask to the same resolution as the new background, ensuring edge alignment and compositing accuracy.

Notes

Please note that when width or height is set to 0 and "Keep Proportions" is enabled, the node will use the mask's original dimension as the target value for that axis. Additionally, when the "lanczos" upsampling method is selected, the internal processing mechanism differs slightly from other methods, but the final output result is consistent.

The Resize Mask node is from the ComfyUI-KJNodes node package.

Comments

Sign in with GitHub to join the discussion.

Loading comments…