ComfyUI > Nodes > ComfyUI-UniversalToolkit > Color To Mask (UTK)

ComfyUI Node: Color To Mask (UTK)

Class Name

ColorToMask_UTK

Category
UniversalToolkit/Tools
Author
whmc76 (Account age: 1110days)
Extension
ComfyUI-UniversalToolkit
Latest Updated
2026-03-16
Github Stars
0.07K

How to Install ComfyUI-UniversalToolkit

Install this extension via the ComfyUI Manager by searching for ComfyUI-UniversalToolkit
  • 1. Click the Manager button in the main menu
  • 2. Select Custom Nodes Manager button
  • 3. Enter ComfyUI-UniversalToolkit in the search bar
After installation, click the Restart button to restart ComfyUI. Then, manually refresh your browser to clear the cache and access the updated list of nodes.

Visit ComfyUI Online for ready-to-use ComfyUI environment

  • Free trial available
  • 16GB VRAM to 80GB VRAM GPU machines
  • 400+ preloaded models/nodes
  • Freedom to upload custom models/nodes
  • 200+ ready-to-run workflows
  • 100% private workspace with up to 200GB storage
  • Dedicated Support

Run ComfyUI Online

Color To Mask (UTK) Description

Converts specific image colors to masks using RGB and threshold for color-based segmentation.

Color To Mask (UTK):

The ColorToMask_UTK node is designed to convert specific colors within an image into a mask, based on a defined RGB color and a threshold for color similarity. This node is particularly useful for isolating areas of an image that match a specific color, allowing you to create masks that highlight or exclude these areas. By calculating the Euclidean distance between each pixel's color and the target RGB color, the node determines which pixels fall within the specified threshold distance. These pixels are included in the mask, appearing as white, while those outside the threshold are excluded and appear as black. This functionality is beneficial for tasks such as chroma keying or color-based segmentation in image processing workflows.

Color To Mask (UTK) Input Parameters:

images

This parameter accepts the input images that you want to convert into masks. The images are analyzed to identify pixels that match the specified color criteria.

red

This integer parameter specifies the red component of the target color you wish to match in the image. It ranges from 0 to 255, with a default value of 0. Adjusting this value changes the red intensity of the target color.

green

This integer parameter specifies the green component of the target color. It also ranges from 0 to 255, with a default value of 0. Modifying this value alters the green intensity of the target color.

blue

This integer parameter specifies the blue component of the target color. Like the other color components, it ranges from 0 to 255, with a default value of 0. Changing this value affects the blue intensity of the target color.

threshold

This integer parameter defines the maximum color distance for a pixel to be included in the mask. It ranges from 0 to 255, with a default value of 10. A lower threshold results in a stricter color match, while a higher threshold allows for more variation in color similarity.

invert

This boolean parameter determines whether to invert the mask. By default, it is set to False. When enabled, the mask will exclude pixels that match the target color, effectively inverting the mask's inclusion criteria.

Color To Mask (UTK) Output Parameters:

mask

The output parameter is a mask that highlights the areas of the input image that match the specified color criteria. Pixels within the threshold distance of the target color are included in the mask and appear as white, while those outside the threshold are excluded and appear as black. This mask can be used for further image processing tasks, such as isolating specific regions or applying effects selectively.

Color To Mask (UTK) Usage Tips:

  • To achieve precise color matching, start with a lower threshold value and gradually increase it until the desired areas are included in the mask.
  • Use the invert option to exclude specific colors from the mask, which can be useful for removing unwanted backgrounds or elements from an image.
  • Experiment with different RGB values to isolate various colors in an image, especially when working with complex scenes or multiple objects.

Color To Mask (UTK) Common Errors and Solutions:

Mask is None

  • Explanation: This error occurs when the input image is not properly loaded or processed, resulting in a null mask.
  • Solution: Ensure that the input image is correctly formatted and accessible. Check for any issues with the image file or path.

Failed to convert mask to PIL

  • Explanation: This error indicates a failure in converting the mask to a PIL image format, possibly due to incompatible image data.
  • Solution: Verify that the input image is in a supported format and that the image processing libraries are correctly installed and configured.

Mask size exceeds limit

  • Explanation: This error occurs when the mask's dimensions exceed the maximum allowed size, which can lead to performance issues.
  • Solution: Consider resizing the input image or adjusting the processing parameters to reduce the mask size.

Color To Mask (UTK) Related Nodes

Go back to the extension to check out more related nodes.
ComfyUI-UniversalToolkit
RunComfy
Copyright 2025 RunComfy. All Rights Reserved.

RunComfy is the premier ComfyUI platform, offering ComfyUI online environment and services, along with ComfyUI workflows featuring stunning visuals. RunComfy also provides AI Models, enabling artists to harness the latest AI tools to create incredible art.

Color To Mask (UTK)