Batch Crop From Mask(BatchCropFromMask)
From a technical implementation perspective, this node takes an original image of type `IMAGE` and a mask of type `MASK` as inputs.
Batch Crop From Mask
From a technical implementation perspective, the Batch Crop From Mask node takes the original image of type IMAGE and a mask of type MASK as input.
The Batch Crop From Mask node is a tool for batch image processing. It can automatically identify and crop target regions within images based on provided masks. The core functionality of this node is to analyze the non-zero pixel areas of each mask, calculate the corresponding bounding boxes, and use these bounding boxes to crop the corresponding sub-images from the original images.
Node Functionality
From a technical implementation perspective, this node takes the original image of type IMAGE and a mask of type MASK as input. It iterates through each pair of image and mask, calculating the minimum bounding rectangle based on the coordinates of non-zero pixels in the mask. The node supports smoothing the size of the bounding box. The bbox_smooth_alpha parameter adjusts the blending degree between the current frame's bounding box size and the historical frame's bounding box size, which helps achieve more stable cropping results in sequence processing. The calculated bounding box size is also scaled by multiplying it with the crop_size_mult coefficient to flexibly adjust the final cropping area size.
Node Parameter Description - Batch Crop From Mask
Connection Inputs (Inputs)
| Parameter Name | Data Type | Required | Default Value | Value Range/Options | Description |
|---|---|---|---|---|---|
original_images | IMAGE | Yes | - | - | **: The output original image sequence, identical to the input. Type is IMAGE. |
masks | MASK | Yes | - | - | **: The input mask sequence, used to determine the target area to be cropped from the original image. Non-zero pixel areas in the mask will be calculated as the bounding box. Type is MASK. |
Control Parameters (Parameters)
| Parameter Name | Data Type | Required | Default Value | Value Range/Options | Description |
|---|---|---|---|---|---|
crop_size_mult | FLOAT | Yes | 1.0 | 0.0 - 10.0 (Step: 0.001) | **: Crop size multiplier, used to scale the calculated bounding box size. Value range 0.0 to 10.0, step 0.001. |
bbox_smooth_alpha | FLOAT | Yes | 0.5 | 0.0 - 1.0 (Step: 0.01) | **: Bounding box smoothing coefficient, used to blend the current frame's bounding box size with the previous frame's for smooth transitions. Value range 0.0 to 1.0, step 0.01. |
Output
| Parameter Name | Data Type | Description |
|---|---|---|
| original_images | IMAGE | **: The output original image sequence, identical to the input. Type is IMAGE. |
| cropped_images | IMAGE | **: The output cropped image sequence. Type is IMAGE. |
| bboxes | BBOX | **: The output bounding box coordinate sequence, formatted as (x1, y1, x2, y2). Type is BBOX. |
| width | INT | **: The unified width of the output cropped images. Type is INT. |
| height | INT | **: The unified height of the output cropped images. Type is INT. |
Usage Scenarios
In practical workflows, this node is commonly used in scenarios requiring focus on specific parts of an image. For example, when creating animations or processing video sequences, you can first use a mask generation node (such as SAM or GroundingDino) to identify the main object in each frame. Then, connect the generated mask sequence and the original image sequence to this node. The node will output the cropped image sequence and the corresponding bounding box coordinates. These outputs can be further used for local inpainting, super-resolution, or as input for other image processing nodes.
Batch Crop From Mask Node Source Code Link
The Batch Crop From Mask node is from the ComfyUI-KJNodes node package.
Comments
Sign in with GitHub to join the discussion.