ComfyUI > Nodes > ComfyUI-Grounding > Batch Crop and Pad From Mask

ComfyUI Node: Batch Crop and Pad From Mask

Class Name

BatchCropAndPadFromMask

Category
grounding
Author
PozzettiAndrea (Account age: 2240days)
Extension
ComfyUI-Grounding
Latest Updated
2025-12-22
Github Stars
0.03K

How to Install ComfyUI-Grounding

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

Batch Crop and Pad From Mask Description

Efficiently crops and pads images using masks for precise region isolation and batch processing.

Batch Crop and Pad From Mask:

The BatchCropAndPadFromMask node is designed to efficiently process images by cropping and padding them based on provided masks. This node is particularly useful in scenarios where you need to isolate specific regions of an image for further analysis or processing. By leveraging masks, it allows for precise extraction of image segments, ensuring that only the areas of interest are retained while the rest are padded according to specified parameters. This functionality is beneficial for tasks such as object detection, segmentation, and image preprocessing, where maintaining the integrity of the region of interest is crucial. The node's ability to handle batches of images and masks simultaneously makes it a powerful tool for processing large datasets efficiently.

Batch Crop and Pad From Mask Input Parameters:

images

This parameter represents the batch of images that you want to process. Each image in the batch will be cropped and padded based on the corresponding mask. The images should be provided in a format that the node can interpret, typically as a list or array of image data.

masks

The masks parameter is a batch of masks corresponding to the images. Each mask defines the region of interest within the respective image. The node uses these masks to determine which parts of the image to crop and which to pad. Masks should be provided in a compatible format, such as a list of arrays, where each array corresponds to an image in the batch.

padding_mode

This parameter specifies the mode of padding to be applied to the cropped images. Common options include "constant", "reflect", or "edge", each determining how the padding is filled. The default is typically "constant", which fills the padding with a specified color.

padding_color_r, padding_color_g, padding_color_b

These parameters define the RGB color values used for padding when the padding_mode is set to "constant". They allow you to specify the exact color that will fill the padded areas, with default values often set to 255, which corresponds to white.

crop_size_mult

The crop_size_mult parameter is a multiplier that adjusts the size of the cropped region. A value of 1.0 means the crop size is determined solely by the mask, while values greater than 1.0 increase the crop size proportionally. This can be useful for ensuring that the cropped region includes some context around the mask.

Batch Crop and Pad From Mask Output Parameters:

cropped_images

This output contains the batch of images that have been cropped and padded according to the provided masks and parameters. Each image in this batch corresponds to an input image, with the specified regions of interest isolated and the rest padded as defined.

masks_batch

The masks_batch output provides the processed masks that correspond to the cropped and padded images. These masks reflect the regions of interest in the output images, allowing for easy identification and further processing of these areas.

Batch Crop and Pad From Mask Usage Tips:

  • Ensure that your masks accurately represent the regions of interest in your images to achieve optimal cropping results.
  • Experiment with different padding_mode settings to see which best suits your needs, especially if the context around the cropped region is important.
  • Use the crop_size_mult parameter to include additional context around the cropped area, which can be beneficial for tasks that require some surrounding information.

Batch Crop and Pad From Mask Common Errors and Solutions:

"Invalid mask format"

  • Explanation: This error occurs when the masks provided are not in a format that the node can process.
  • Solution: Ensure that your masks are in a compatible format, such as a list of numpy arrays, where each array corresponds to an image in the batch.

"Image and mask batch size mismatch"

  • Explanation: This error indicates that the number of images does not match the number of masks provided.
  • Solution: Verify that each image in your batch has a corresponding mask and that both batches are of the same size.

"Unsupported padding mode"

  • Explanation: The specified padding_mode is not recognized by the node.
  • Solution: Check the available padding modes and ensure you are using a supported option, such as "constant", "reflect", or "edge".

Batch Crop and Pad From Mask Related Nodes

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