ComfyUI  >  Nodes  >  Masquerade Nodes >  Create Rect Mask

ComfyUI Node: Create Rect Mask

Class Name

Create Rect Mask

Category
Masquerade Nodes
Author
BadCafeCode (Account age: 485 days)
Extension
Masquerade Nodes
Latest Updated
6/19/2024
Github Stars
0.3K

How to Install Masquerade Nodes

Install this extension via the ComfyUI Manager by searching for  Masquerade Nodes
  • 1. Click the Manager button in the main menu
  • 2. Select Custom Nodes Manager button
  • 3. Enter Masquerade Nodes 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
  • High-speed GPU machines
  • 200+ preloaded models/nodes
  • Freedom to upload custom models/nodes
  • 50+ ready-to-run workflows
  • 100% private workspace with up to 200GB storage
  • Dedicated Support

Run ComfyUI Online

Create Rect Mask Description

Generate rectangular masks within images for isolating specific regions with adjustable position, size, and origin point.

Create Rect Mask:

The Create Rect Mask node is designed to generate a rectangular mask within an image, which can be particularly useful for isolating specific regions for further processing or analysis. This node allows you to define the position and size of the rectangle either in pixels or as a percentage of the image dimensions. Additionally, it offers flexibility in setting the origin point of the rectangle, making it adaptable to various use cases. If an image is provided through the copy_image_size parameter, the node will automatically adjust the mask size to match the dimensions of the given image, ensuring seamless integration with your existing workflow. This functionality is essential for tasks that require precise control over masked areas, such as image editing, object detection, and region-based filtering.

Create Rect Mask Input Parameters:

mode

This parameter determines the unit of measurement for the rectangle's dimensions and position. It can be set to either "percent" or "pixels". When set to "percent", the values for x, y, width, and height are interpreted as percentages of the image's width and height. When set to "pixels", these values are taken as absolute pixel measurements. This flexibility allows you to choose the most convenient unit for your specific task.

origin

This parameter specifies the reference point for the rectangle's position. It can be set to one of the following options: "topleft", "bottomleft", "topright", or "bottomright". The chosen origin affects how the x and y coordinates are interpreted, providing you with control over the rectangle's alignment within the image.

x

This parameter sets the horizontal position of the rectangle's origin. Its value can range from 0 to a very large size, with a default of 0. The interpretation of this value depends on the mode parameter, either as a percentage or in pixels.

y

This parameter sets the vertical position of the rectangle's origin. Its value can range from 0 to a very large size, with a default of 0. Similar to x, the interpretation of this value depends on the mode parameter.

width

This parameter defines the width of the rectangle. Its value can range from 0 to a very large size, with a default of 50. The unit of this value is determined by the mode parameter, allowing you to specify the width in either pixels or as a percentage of the image width.

height

This parameter defines the height of the rectangle. Its value can range from 0 to a very large size, with a default of 50. The unit of this value is determined by the mode parameter, allowing you to specify the height in either pixels or as a percentage of the image height.

image_width

This parameter sets the width of the image in pixels. It is used when the copy_image_size parameter is not provided. The value can range from 64 to a very large size, with a default of 512. This parameter ensures that the mask is created with the correct dimensions.

image_height

This parameter sets the height of the image in pixels. It is used when the copy_image_size parameter is not provided. The value can range from 64 to a very large size, with a default of 512. This parameter ensures that the mask is created with the correct dimensions.

copy_image_size

This optional parameter allows you to provide an image whose dimensions will be used for the mask, overriding the image_width and image_height parameters. This ensures that the mask fits perfectly within the provided image, simplifying the process of creating masks for existing images.

Create Rect Mask Output Parameters:

IMAGE

The output of this node is an image containing the rectangular mask. The mask is represented as a binary image where the masked area is set to 1 and the rest of the image is set to 0. This output can be used in subsequent nodes for various image processing tasks, such as filtering, segmentation, or object detection.

Create Rect Mask Usage Tips:

  • To create a mask that covers a specific region of an image, use the "pixels" mode and provide exact pixel values for x, y, width, and height.
  • For masks that need to scale with different image sizes, use the "percent" mode to define the rectangle's dimensions and position as percentages of the image's width and height.
  • Utilize the copy_image_size parameter to automatically adjust the mask size to match the dimensions of an existing image, ensuring seamless integration with your workflow.

Create Rect Mask Common Errors and Solutions:

"Invalid mode value"

  • Explanation: The mode parameter must be set to either "percent" or "pixels".
  • Solution: Ensure that the mode parameter is correctly set to one of the allowed values.

"Invalid origin value"

  • Explanation: The origin parameter must be set to one of the following: "topleft", "bottomleft", "topright", or "bottomright".
  • Solution: Verify that the origin parameter is correctly set to one of the allowed values.

"x, y, width, or height out of range"

  • Explanation: The values for x, y, width, and height must be within the specified range.
  • Solution: Check that the values for these parameters are within the allowed range and adjust them if necessary.

"Invalid image dimensions"

  • Explanation: The image_width and image_height parameters must be within the specified range.
  • Solution: Ensure that the values for image_width and image_height are within the allowed range and adjust them if necessary.

"copy_image_size not provided"

  • Explanation: If the copy_image_size parameter is used, it must be a valid image.
  • Solution: Provide a valid image for the copy_image_size parameter or ensure that it is not used if not needed.

Create Rect Mask Related Nodes

Go back to the extension to check out more related nodes.
Masquerade Nodes
RunComfy

© Copyright 2024 RunComfy. All Rights Reserved.

RunComfy is the premier ComfyUI platform, offering ComfyUI online environment and services, along with ComfyUI workflows featuring stunning visuals.