ComfyUI > Nodes > D2 Nodes ComfyUI > D2 Cut By Mask

ComfyUI Node: D2 Cut By Mask

Class Name

D2 Cut By Mask

Category
D2/Image
Author
da2el-ai (Account age: 713days)
Extension
D2 Nodes ComfyUI
Latest Updated
2025-05-04
Github Stars
0.03K

How to Install D2 Nodes ComfyUI

Install this extension via the ComfyUI Manager by searching for D2 Nodes ComfyUI
  • 1. Click the Manager button in the main menu
  • 2. Select Custom Nodes Manager button
  • 3. Enter D2 Nodes ComfyUI 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

D2 Cut By Mask Description

Extract specific image regions using masks for precise editing, with options for shape, size, and alpha channel control.

D2 Cut By Mask:

The D2 Cut By Mask node is designed to extract specific regions from an image using a mask. This node is particularly useful for isolating parts of an image based on a defined mask, allowing for precise image manipulation and editing. It offers flexibility in how the image is cut, whether following the exact shape of the mask, creating a rectangular cutout, or generating a square thumbnail centered on the mask area. This functionality is beneficial for tasks that require focused image processing, such as creating thumbnails, isolating objects, or preparing images for further compositing. By providing options to adjust the output size and include an alpha channel, the node ensures that the extracted image meets specific requirements, making it a versatile tool in image processing workflows.

D2 Cut By Mask Input Parameters:

images

This parameter represents the source images from which regions will be extracted. The images should be in a compatible format, typically a batch of images with dimensions [batch, height, width, channels]. The quality and resolution of the input images directly affect the output, as the node will cut based on the provided mask and image dimensions.

mask

The mask parameter defines the area of the image to be extracted. It can be a binary mask where non-zero values indicate the region of interest. The mask should match the dimensions of the input images to ensure compatibility. The mask's shape determines the cutout area, and it can be adjusted to fit the image dimensions using utility functions.

cut_type

This parameter specifies the shape of the cutout. Options include "mask" for cutting according to the mask's shape, "rectangle" for creating a rectangular cutout based on the mask's bounding box, and "square_thumb" for generating a square thumbnail centered on the mask area. The choice of cut_type affects the final appearance of the extracted region.

output_size

This parameter determines the size of the output image. Options include "mask_size" for an output that matches the mask's dimensions, and "image_size" for an output that retains the input image's size with transparency around the cutout. The output_size setting influences how the extracted region is presented and can be tailored to specific needs.

padding

Padding allows for the expansion of the mask area by a specified number of pixels. The default value is 0, meaning no expansion. Increasing the padding can help include additional context around the mask area, which can be useful for certain image processing tasks.

min_width

This parameter sets the minimum width for the mask size. The default value is 0, and it can be adjusted up to 10000 pixels. Ensuring a minimum width can be important for maintaining consistency in the output, especially when dealing with varying mask sizes.

min_height

Similar to min_width, this parameter sets the minimum height for the mask size. The default value is 0, with a maximum of 10000 pixels. It ensures that the extracted region meets a certain height requirement, which can be crucial for uniformity in image processing.

output_alpha

This boolean parameter determines whether the output image includes an alpha channel. The default is true, meaning the output will have transparency information. Including an alpha channel is essential for compositing tasks where the extracted region needs to be overlaid on other images.

D2 Cut By Mask Output Parameters:

image

The image output is the region extracted from the input image based on the mask and cut_type. It reflects the specified output_size and may include an alpha channel if output_alpha is true. This output is crucial for further image processing or compositing tasks.

mask

The mask output is the mask used for the extraction, which can be the original mask or adjusted based on the output_size setting. It provides a reference for the extracted region and can be used for additional processing or analysis.

rect

The rect output provides the coordinates and dimensions of the extracted region in the format (x, y, width, height). This information is valuable for understanding the position and size of the cutout within the original image, aiding in precise image manipulation.

D2 Cut By Mask Usage Tips:

  • To create a thumbnail centered on a specific area, use the "square_thumb" cut_type and ensure the mask is centered on the desired region.
  • When working with images that require transparency, set output_alpha to true to include an alpha channel in the output.
  • Use padding to include additional context around the mask area, which can be useful for tasks that require more background information.

D2 Cut By Mask Common Errors and Solutions:

"Mask is required for 'mask' paste mode"

  • Explanation: This error occurs when the mask parameter is not provided, but the cut_type is set to "mask".
  • Solution: Ensure that a valid mask is supplied when using the "mask" cut_type to define the extraction area.

"Empty mask detected, treating the entire image as the rectangle"

  • Explanation: This message indicates that the provided mask is empty, and the node defaults to using the entire image as the cutout area.
  • Solution: Verify that the mask correctly highlights the desired region. If the mask is intentionally empty, consider using a different cut_type or adjust the mask to include the target area.

D2 Cut By Mask Related Nodes

Go back to the extension to check out more related nodes.
D2 Nodes ComfyUI
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 Playground, enabling artists to harness the latest AI tools to create incredible art.