Image Crop By Mask Batch(ImageCropByMaskBatch)
This node takes an image (IMAGE) and a mask (MASK) as input, where the mask is used to define the area to be preserved in the image.
Image Crop By Mask Batch
The Image Crop By Mask Batch node receives an image (IMAGE) and a mask (MASK) as input. The mask is used to define the area to be preserved in the image.
The Image Crop By Mask Batch node is an efficient image processing tool capable of batch-cropping input images based on provided masks. Its core functionality is to automatically identify the mask region and precisely extract that area from the original image, generating new images and their corresponding masks.
Node Functionality
This node receives an image (IMAGE) and a mask (MASK) as input. The mask defines the area to be preserved in the image. The node calculates the bounding box of the effective area for each mask and crops it according to the specified width, height, and padding values. If the mask dimensions do not match the image, the node automatically performs interpolation adjustments. The cropped area is placed at the center of a new canvas and supports custom background colors.
Node Parameter Description - Image Crop By Mask Batch
Connection Inputs (Inputs)
| Parameter Name | Data Type | Required | Default Value | Range/Options | Description |
|---|---|---|---|---|---|
image | IMAGE | Yes | - | - | image (Input Parameter): The original input image to be cropped. |
masks | MASK | Yes | - | - | The masks used to define the cropping region. |
Control Parameters (Parameters)
| Parameter Name | Data Type | Required | Default Value | Range/Options | Description |
|---|---|---|---|---|---|
width | INT | Yes | - | - | width (Input Parameter): The width of the output image after cropping. |
height | INT | Yes | - | - | height (Input Parameter): The height of the output image after cropping. |
padding | INT | Yes | 0 | 0 - 4096 (Step: 1) | padding (Input Parameter): The number of additional pixels to extend beyond the mask region's bounding box, ranging from 0 to 4096. |
preserve_size | BOOLEAN | Yes | False | - | preserve_size (Input Parameter): If True, the width and height parameters are ignored, and the output image retains its original dimensions. |
bg_color | STRING | Yes | 0, 0, 0 | - | Color as RGB values in range 0-255 or 0.0-1.0, or color name or hex code |
Output
| Parameter Name | Data Type | Description |
|---|---|---|
| images | IMAGE | images (Output Parameter): The collection of images generated after cropping based on the masks. |
| masks | MASK | The cropped and adjusted masks. |
Usage Scenarios
This node is highly useful in image inpainting or local repainting workflows. For example, you can first use a mask generation node (such as SAM or Mask Editor) to mark the area in the image that needs modification (e.g., a face). Then, use this node to crop out the marked area for separate detail adjustments or stylization before compositing it back into the original image.
Notes
Please note that the input mask must be a single-channel binary image, where the white (or non-zero) area represents the part to be preserved. If a mask is entirely black (i.e., has no effective area), the corresponding image will not be processed.
Image Crop By Mask Batch Node Source Code Link
The Image Crop By Mask Batch node is from the ComfyUI-KJNodes node package.
Comments
Sign in with GitHub to join the discussion.