Color To Mask(ColorToMask)
This node takes a standard IMAGE tensor as input and internally determines whether a match occurs by calculating the Euclidean distance between each pixel and the target color.
Color To Mask
The Color To Mask node receives a standard IMAGE tensor as input. Internally, it determines whether a pixel matches the target color by calculating the Euclidean distance between each pixel and the target color.
The Color To Mask node is an image processing tool. Its core function is to convert areas in the input image that are similar to a user-specified RGB color value into a black-and-white mask. Through color matching and threshold control, it achieves precise extraction from a color image to a monochrome mask.
Node Function
This node receives a standard IMAGE tensor as input. Internally, it determines whether a pixel matches the target color by calculating the Euclidean distance between each pixel and the target color. Users can define the target color using independent values (0-255) for the red, green, and blue channels, and control the tolerance of color matching via the threshold parameter. The node supports batch processing of images and can optimize memory usage through the per_batch parameter.
Node Parameter Description - Color To Mask
Connection Inputs (Inputs)
| Parameter Name | Data Type | Required | Default Value | Range/Options | Description |
|---|---|---|---|---|---|
images | IMAGE | Yes | - | - | images (Input Parameter): Input the image or batch of images to be processed, in the ComfyUI standard IMAGE tensor format. |
Control Parameters (Parameters)
| Parameter Name | Data Type | Required | Default Value | Range/Options | Description |
|---|---|---|---|---|---|
invert | BOOLEAN | Yes | False | - | invert (Input Parameter): Inverts the output mask. When False, matched areas are white; when True, matched areas become black. |
red | INT | Yes | 0 | 0 - 255 (Step: 1) | red (Input Parameter): Defines the red channel value of the target color, range 0 to 255, step size 1. |
green | INT | Yes | 0 | 0 - 255 (Step: 1) | green (Input Parameter): Defines the green channel value of the target color, range 0 to 255, step size 1. |
blue | INT | Yes | 0 | 0 - 255 (Step: 1) | blue (Input Parameter): Defines the blue channel value of the target color, range 0 to 255, step size 1. |
threshold | INT | Yes | 10 | 0 - 255 (Step: 1) | threshold (Input Parameter): The tolerance threshold for color matching. A smaller value results in more precise matching, range 0 to 255, step size 1. |
per_batch | INT | Yes | 16 | 1 - 4096 (Step: 1) | per_batch (Input Parameter): Controls the number of images processed per batch during batch processing, used to manage memory usage, range 1 to 4096, step size 1. |
Output
| Parameter Name | Data Type | Description |
|---|---|---|
| MASK | MASK | MASK (Output Parameter): The output black-and-white mask, where white areas represent parts matching the target color. |
Usage Scenarios
In practical applications, this node is commonly used in image editing or AI painting workflows to isolate objects or areas of a specific color. For example, you can load a landscape image containing a blue sky background, set the target color to the blue of the sky, and quickly generate a mask for the sky area. This mask can then be used for subsequent individual color grading, replacement, or special effects processing on that area.
Notes
When processing high-resolution images or large batches of images, appropriately reducing the per_batch value can help avoid out-of-memory issues. Furthermore, setting the threshold too low may result in incomplete matching areas, while setting it too high may introduce irrelevant areas. Adjustment is necessary based on the color distribution of the image.
Color To Mask Node Source Code Link
The Color To Mask node is from the ComfyUI-KJNodes node package.
Comments
Sign in with GitHub to join the discussion.