ComfyUI > Nodes > Comfy_Felsirnodes > MaskToCrop

ComfyUI Node: MaskToCrop

Class Name

Mask to Crop

Category
Felsir
Author
Felsir (Account age: 3861days)
Extension
Comfy_Felsirnodes
Latest Updated
2026-03-10
Github Stars
0.02K

How to Install Comfy_Felsirnodes

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

MaskToCrop Description

The Mask to Crop node extracts image regions based on a mask, allowing precise cropping and adjustments.

MaskToCrop:

The Mask to Crop node is designed to intelligently extract a specific region from an image based on a provided mask. This node is particularly useful for AI artists who want to focus on a particular area of an image, ensuring that the selected region is accurately cropped according to the mask's boundaries. By leveraging this node, you can efficiently isolate parts of an image for further processing or analysis, making it an essential tool for tasks that require precision and attention to detail. The node offers flexibility in terms of resolution and aspect ratio adjustments, allowing you to tailor the output to your specific needs, whether you want to maintain the original proportions or fit the cropped area into a predefined size.

MaskToCrop Input Parameters:

image_in

This parameter represents the input image from which a region will be cropped. It is essential as it provides the visual data that will be processed and manipulated based on the mask. The image should be in a format compatible with the node's processing capabilities.

mask_in

The mask input is a crucial parameter that defines the area of interest within the image. It acts as a guide for the cropping operation, ensuring that only the specified region is extracted. The mask should be a binary or grayscale image where the areas to be cropped are highlighted.

resolution

This integer parameter determines the resolution of the cropped output. It allows you to specify the desired size of the cropped region, with a default value of 512, a minimum of 16, and a maximum of 2048. Adjusting this parameter can help maintain image quality and detail in the cropped area.

fit_inside

A boolean parameter that, when set to true, ensures the cropped region fits within the specified resolution without exceeding it. This is useful for maintaining the integrity of the image's aspect ratio while ensuring it fits within a particular size constraint.

force_square

This boolean parameter, when enabled, forces the cropped region to be square. This is particularly useful when a uniform aspect ratio is required for subsequent processing or display purposes. The default setting is true, ensuring consistency in the output shape.

padding

An integer parameter that adds extra space around the cropped region. This can be useful for including additional context or ensuring that the cropped area is not too tightly bound. The default value is 0, with a minimum of 0, allowing you to adjust the padding as needed.

MaskToCrop Output Parameters:

IMAGE

The output image is the cropped version of the input image, extracted based on the mask and adjusted according to the specified parameters. This output is crucial for further processing or analysis, providing a focused view of the area of interest.

rect_left

This integer output represents the left coordinate of the cropped rectangle within the original image. It indicates the horizontal starting point of the cropped region.

rect_top

This integer output indicates the top coordinate of the cropped rectangle within the original image, marking the vertical starting point of the cropped area.

rect_width

The width of the cropped rectangle, represented as an integer, provides the horizontal dimension of the extracted region. This output is essential for understanding the size and scale of the cropped area.

rect_height

This integer output denotes the height of the cropped rectangle, offering the vertical dimension of the extracted region. It helps in assessing the scale and proportions of the cropped output.

MaskToCrop Usage Tips:

  • Ensure that the mask accurately highlights the area you wish to crop to achieve precise results.
  • Use the resolution parameter to maintain image quality, especially when working with high-resolution images.
  • Enable fit_inside to prevent the cropped region from exceeding the desired resolution, maintaining the aspect ratio.
  • Utilize force_square when a uniform aspect ratio is required for consistency across multiple images.

MaskToCrop Common Errors and Solutions:

Mask shape mismatch

  • Explanation: This error occurs when the dimensions of the mask do not match the dimensions of the input image.
  • Solution: Ensure that the mask and image have the same dimensions before processing.

Invalid resolution value

  • Explanation: The resolution parameter is set outside the allowed range.
  • Solution: Adjust the resolution to be within the specified range of 16 to 2048.

Padding exceeds image dimensions

  • Explanation: The padding value is too large, causing the cropped area to exceed the image boundaries.
  • Solution: Reduce the padding value to ensure it fits within the image dimensions.

MaskToCrop Related Nodes

Go back to the extension to check out more related nodes.
Comfy_Felsirnodes
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.