Run ComfyUI Easily with InstaSD

Skip the complex setup. InstaSD helps creative professionals build workflows and deploy them to the world:

  • One-click deployment
  • Any model, any node
  • Powerful GPUs for rapid iteration
Get Started

Available Nodes

BatchCropFromMaskAdvanced

Documentation for the BatchCropFromMaskAdvanced Node

Overview

The BatchCropFromMaskAdvanced node is part of the ComfyUI project and belongs to the KJNodes collection. This node is designed for advanced image cropping based on mask data. It enhances image processing workflows by enabling precise cropping operations that consider mask boundaries, smoothing transitions, and maintaining consistent cropping dimensions across batches.

Functional Description

The BatchCropFromMaskAdvanced node processes batches of images and their corresponding masks to perform cropping operations. The node determines the most effective crop boundaries by considering non-zero regions in masks, smoothing bounding box transitions, and applying a crop size multiplier. It ensures that the cropped dimensions are consistent, making it especially useful for workflows where maintaining uniformity in image sizes is crucial.

Inputs

The node accepts the following inputs:

  • Original Images: Batches of images that are to be cropped. These images serve as the source for cropping operations.
  • Masks: Batches of corresponding masks indicating regions of interest within each image. Non-zero regions in these masks determine where crops are made.
  • Crop Size Multiplier: A scaling factor applied to the determined bounding box size, enabling control over the size of the cropped area.
  • Bounding Box Smoothing Alpha: A smoothing parameter that controls the transition of bounding box size and position across frames, mitigating abrupt changes.

Outputs

The node produces multiple outputs:

  • Original Images: Returns the original batch of images unchanged. This is useful for reference or for further processing steps.
  • Cropped Images: Returns images that have been cropped based on the mask data and bounding box calculations.
  • Cropped Masks: The corresponding cropped sections of the original masks, aligning with the cropped images.
  • Combined Crop Image: A merged version of the cropped images, illustrating the combination of all cropped segments.
  • Combined Crop Masks: A merged version of the cropped masks.
  • Bounding Boxes: Data for each frame indicating the coordinates of the cropping bounding box.
  • Combined Bounding Box: A singular bounding box that can encompass regions from all combined masks.
  • Bounding Box Width and Height: The dimensions of the bounding boxes used for cropping operations.

Usage in ComfyUI Workflows

The BatchCropFromMaskAdvanced node is invaluable in workflows requiring precise image processing based on areas of interest defined by masks. Example applications include:

  • Object Detection and Recognition: Extract specific regions of interest from images for further analysis or recognition tasks.
  • Image Segmentation: Enhance segmentation workflows by providing standardized cropping operations across multiple images and masks.
  • Image Augmentation: Create uniform image datasets for deep learning models where consistent image size is essential.

Special Features and Considerations

  • Smooth Transitions: The usage of smooth transitions for bounding box size and center helps in maintaining visual consistency across frames, particularly useful in video processing or sequential data.
  • Aspect Ratio Handling: The node ensures that the aspect ratio of the cropped regions remains consistent, which is critical for downstream tasks that require uniform image dimensions.
  • Mask Combination: By utilizing both individual and combined cropping strategies, the node offers flexibility in handling complex masking scenarios, providing comprehensive options for image processing.

The BatchCropFromMaskAdvanced node provides advanced features for handling complex image cropping operations, making it a powerful tool in the ComfyUI toolkit for developers and researchers working with image and video data.