ComfyUI-KJNodes
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
Available Nodes
BatchCropFromMask
BatchCropFromMask Node Documentation
Introduction
The BatchCropFromMask node is a specialized component of the ComfyUI that enables users to crop multiple images based on corresponding masks. By analyzing non-zero areas in the masks, this node determines bounding boxes and extracts the relevant portions of the images accordingly. This is especially useful when dealing with batches of images where specific regions of interest are defined by masks.
Functionality
The BatchCropFromMask node processes input images and masks to output cropped images and related data. For each image-mask pair, it computes the bounding box from the mask, applies a size multiplier, optionally smooths the size and position of these bounding boxes over the batch to stabilize variance across frames, and produces cropped images based on these bounding boxes.
Inputs
The BatchCropFromMask node requires the following inputs:
- original_images: A batch of images from which corresponding regions are to be cropped.
- masks: A set of masks indicating the areas of interest within each image. These are used to determine bounding boxes.
- crop_size_mult: A floating-point multiplier to adjust the size of the bounding boxes. Increasing this value enlarges the crop area, while reducing it shrinks the crop area.
- bbox_smooth_alpha: A smoothing factor for bounding box size and position, ranging from 0 to 1. This factor determines how much influence previous bounding box dimensions and positions have on the current frame’s bounding box.
Outputs
The node produces the following outputs:
- original_images: The original batch of input images. This is often used downstream to ensure consistency.
- cropped_images: Images cropped according to the calculated bounding boxes.
- bboxes: A list of the bounding box dimensions for each mask, indicating the area that was cropped.
- width: The maximum width of the cropped bounding boxes.
- height: The maximum height of the cropped bounding boxes.
Usage in ComfyUI Workflows
The BatchCropFromMask node is typically deployed in workflows where users need to isolate specific areas from image batches for further processing or analysis, such as object detection, segmentation, or custom preprocessing pipelines. Common usage scenarios include:
- Preprocessing image batches for machine learning applications where each image’s relevant area is dynamically determined by masks.
- Extracting object-focused portions of images in image editing or compositing tasks.
- Preparing datasets where uniformly cropped regions are needed across frames, such as in video processing or animation.
Special Features and Considerations
- Bounding Box Smoothing: The node incorporates a smoothing feature for bounding box dimensions and center positions, allowing for stable transitions across frames, beneficial in video processing or when dealing with temporally related images.
- Aspect Ratio Preservation: The cropping mechanism considers aspect ratios, ensuring the output images maintain natural proportions, particularly when the
crop_size_multis applied. - Batch Processing: The node is designed to handle batches of images and masks, offering scalability and speed for processing large image datasets or sequences.
- Performance Impact: Given the computation involved in analyzing masks and resizing images, performance considerations should be made when handling very large images or extensive batches.
By integrating the BatchCropFromMask node within a ComfyUI workflow, users gain fine-tuned control over image cropping operations, particularly useful in dynamic environments where manual cropping is impractical.