ComfyUI > Nodes > ComfyUI-UniversalToolkit > Crop By Mask (UTK)

ComfyUI Node: Crop By Mask (UTK)

Class Name

CropByMask_UTK

Category
UniversalToolkit/Image
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

Crop By Mask (UTK) Description

The CropByMask_UTK node crops images precisely using a specified mask for targeted processing.

Crop By Mask (UTK):

The CropByMask_UTK node is designed to facilitate the precise cropping of images based on a specified mask. This node is particularly useful for AI artists who need to isolate specific regions of an image for further processing or analysis. By leveraging a mask, which acts as a guide, the node identifies the area of interest and crops the image accordingly. This process is beneficial for tasks that require focused attention on certain parts of an image, such as enhancing details or applying effects selectively. The node ensures that the cropped region is accurately aligned with the mask, providing a seamless and efficient workflow for image manipulation.

Crop By Mask (UTK) Input Parameters:

image

The image parameter represents the input image that you wish to crop. It is essential for the node to have an image to process, as the cropping operation is performed on this input. The image should be in a compatible format that the node can interpret and manipulate.

mask_for_crop

The mask_for_crop parameter is a crucial input that defines the region of the image to be cropped. This mask acts as a stencil, highlighting the area of interest. If multiple masks are provided, the node will use the first one. The mask should be a binary or grayscale image where the area to be cropped is marked distinctly.

invert_mask

The invert_mask parameter is a boolean option that allows you to invert the mask before cropping. When set to true, the areas marked in the mask will be inverted, effectively swapping the regions to be cropped and ignored. This can be useful when you want to exclude a specific area rather than include it.

detect

The detect parameter determines the method used to identify the cropping region. Options include "min_bounding_rect" for the smallest rectangle that can enclose the mask, "max_inscribed_rect" for the largest rectangle that fits within the mask, and "mask_area" for using the entire mask area. This choice affects the shape and size of the cropped region.

padding

The padding parameter allows you to add extra space around the cropped region. This can be useful if you want to include some context around the area of interest. The padding value is added to all sides of the detected crop region, ensuring that the final cropped image includes a buffer zone.

min_crop_resolution

The min_crop_resolution parameter sets the minimum allowable size for the cropped region. If the detected crop area is smaller than this value, it will be adjusted to meet the minimum resolution. This ensures that the cropped image is not too small for practical use.

max_crop_resolution

The max_crop_resolution parameter sets the maximum allowable size for the cropped region. If the detected crop area exceeds this value, it will be reduced to fit within the maximum resolution. This helps maintain a manageable size for the cropped image.

Crop By Mask (UTK) Output Parameters:

ret_images

The ret_images output contains the cropped images resulting from the operation. Each image corresponds to a region defined by the mask, providing a focused view of the area of interest. This output is essential for further processing or analysis of the cropped content.

ret_masks

The ret_masks output provides the masks corresponding to the cropped images. These masks are useful for understanding the exact regions that were cropped and can be used for additional operations or as references in subsequent tasks.

crop_box

The crop_box output is a list that defines the coordinates and dimensions of the cropping region. It includes the x and y positions, as well as the width and height of the crop. This information is valuable for understanding the spatial context of the cropped area within the original image.

preview_image

The preview_image output offers a visual representation of the cropped region, often with the cropping box drawn on the original image. This preview helps in verifying the accuracy of the cropping operation and provides a quick reference for the results.

remaining_masks

The remaining_masks output contains masks that represent the areas of the original image that were not included in the crop. These masks are useful for understanding what was excluded and can be used for further processing or analysis.

Crop By Mask (UTK) Usage Tips:

  • Ensure that your mask is accurately aligned with the area you wish to crop to achieve precise results.
  • Use the invert_mask option if you need to exclude a specific area rather than include it, providing flexibility in your cropping operations.
  • Adjust the padding parameter to include additional context around the cropped region, which can be useful for maintaining visual continuity.
  • Set appropriate values for min_crop_resolution and max_crop_resolution to ensure that the cropped image meets your size requirements.

Crop By Mask (UTK) Common Errors and Solutions:

Masked area out of bounds

  • Explanation: This error occurs when the detected crop region exceeds the boundaries of the original image.
  • Solution: Ensure that your mask is correctly positioned within the image boundaries and adjust the padding or crop detection method if necessary.

Multiple mask inputs, using the first

  • Explanation: This warning indicates that multiple masks were provided, but only the first one will be used for cropping.
  • Solution: If you intended to use a specific mask, ensure that it is the first in the list or adjust your input to include only the desired mask.

Input mask dimensions mismatch

  • Explanation: This error arises when the dimensions of the input mask do not match the expected size.
  • Solution: Verify that your mask dimensions align with the input image and adjust them if necessary to ensure compatibility.

Crop By 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.

Crop By Mask (UTK)