ComfyUI  >  Nodes  >  KJNodes for ComfyUI >  Batch Crop From Mask Advanced

ComfyUI Node: Batch Crop From Mask Advanced

Class Name


kijai (Account age: 2192 days)
KJNodes for ComfyUI
Latest Updated
Github Stars

How to Install KJNodes for ComfyUI

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

Batch Crop From Mask Advanced Description

Sophisticated node for cropping images based on masks, ensuring consistent aspect ratio and size in batch processing for AI art.

Batch Crop From Mask Advanced:

BatchCropFromMaskAdvanced is a sophisticated node designed to crop multiple images based on their corresponding masks. This node is particularly useful for AI artists who need to isolate specific regions of interest within a batch of images, ensuring that the cropped areas are consistent and optimized for further processing. By calculating the maximum bounding box size across all masks and applying a smoothing function, this node ensures that the cropped regions maintain a consistent aspect ratio and size, which is crucial for tasks that require uniformity. The node also allows for the application of a crop size multiplier, giving you control over the final dimensions of the cropped images. This advanced functionality makes BatchCropFromMaskAdvanced an essential tool for batch processing in AI art projects, where precision and consistency are key.

Batch Crop From Mask Advanced Input Parameters:


This parameter represents the collection of masks that will be used to determine the regions to be cropped from the original images. Each mask should correspond to an image in the original_images parameter. The masks are used to identify the non-zero regions, which define the bounding boxes for cropping.


This parameter is the collection of original images from which the regions defined by the masks will be cropped. Each image should correspond to a mask in the masks parameter. The images are processed in conjunction with the masks to produce the final cropped outputs.


This parameter is a multiplier that adjusts the size of the bounding boxes used for cropping. By applying this multiplier, you can control the final dimensions of the cropped images. The default value is typically 1, but you can increase or decrease it to get larger or smaller cropped regions, respectively.


This parameter is used to smooth the changes in the bounding box size across the batch of masks. It helps in maintaining a consistent size for the bounding boxes, which is important for ensuring uniformity in the cropped images. The value of bbox_smooth_alpha typically ranges from 0 to 1, where a higher value results in smoother transitions.

Batch Crop From Mask Advanced Output Parameters:


This output parameter contains the collection of images that have been cropped based on the regions defined by the masks. Each cropped image corresponds to an original image and its mask, and the dimensions are adjusted according to the crop_size_mult and bbox_smooth_alpha parameters.


This output parameter provides the bounding boxes used for cropping each image. These bounding boxes are calculated based on the non-zero regions in the masks and are adjusted for size and aspect ratio consistency. This information can be useful for further processing or analysis of the cropped regions.

Batch Crop From Mask Advanced Usage Tips:

  • Ensure that each mask in the masks parameter corresponds to an image in the original_images parameter to avoid mismatches.
  • Use the crop_size_mult parameter to control the size of the cropped regions. Increasing the multiplier will result in larger cropped areas, while decreasing it will produce smaller regions.
  • Adjust the bbox_smooth_alpha parameter to achieve smoother transitions in bounding box sizes across the batch. A higher value will result in more consistent sizes, which is useful for maintaining uniformity in the cropped images.

Batch Crop From Mask Advanced Common Errors and Solutions:

"Mask and image count mismatch"

  • Explanation: This error occurs when the number of masks does not match the number of original images.
  • Solution: Ensure that the masks and original_images parameters contain the same number of elements.

"Empty mask detected"

  • Explanation: This error occurs when a mask contains no non-zero regions, making it impossible to define a bounding box.
  • Solution: Check the masks to ensure they contain valid regions for cropping. Remove or replace any empty masks.

"Invalid crop size multiplier"

  • Explanation: This error occurs when the crop_size_mult parameter is set to an invalid value, such as a negative number.
  • Solution: Set the crop_size_mult parameter to a positive value to ensure valid cropping dimensions.

"Bounding box calculation error"

  • Explanation: This error occurs when there is an issue with calculating the bounding boxes from the masks.
  • Solution: Verify that the masks are correctly formatted and contain valid non-zero regions. Ensure that the bbox_smooth_alpha parameter is set within the appropriate range.

Batch Crop From Mask Advanced Related Nodes

Go back to the extension to check out more related nodes.
KJNodes for ComfyUI

© 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.