Documentation for LayerUtility: CropByMask V2 Node
Overview
The LayerUtility: CropByMask V2
node is a utility node within the ComfyUI framework. Its primary function is to crop images based on specified mask conditions, providing more targeted and refined image processing capabilities. This node is useful in workflows where precise image cropping is required, especially when dealing with specific regions of interest within an image.
Functionality
What This Node Does
The CropByMask V2
node processes an image and a corresponding mask to produce a cropped version of the image. The cropping is performed based on specified detection modes and reserves certain margins around the detected bounding area. This allows users to refine the area of interest within an image accurately.
Inputs
The node accepts the following inputs:
- Image: The main input image that needs to be processed. This is a required input.
- Mask: A mask image that defines which parts of the main image should be considered for cropping. This is a required input.
- Invert Mask: A boolean option that allows the user to invert the mask. If set to
True
, the mask's black and white areas are inverted.
- Detect: A choice between detection modes that determine how the cropping area is calculated:
mask_area
: Crops based on the mask's overall area.
min_bounding_rect
: Finds the minimum bounding rectangle around the mask.
max_inscribed_rect
: Finds the maximum inscribed rectangle within the mask.
- Top Reserve, Bottom Reserve, Left Reserve, Right Reserve: Integer values specifying the additional margin to reserve on each side of the cropped box.
- Round to Multiple: Allows specifying a number ('8', '16', '32', etc.) to which the cropped dimensions will be rounded. This facilitates compatibility with certain image processing requirements.
Outputs
The node produces the following outputs:
- Cropped Image: The image resulting from the cropping operation.
- Cropped Mask: The mask corresponding to the cropped image area.
- Crop Box: The bounding box coordinates used for cropping, expressed as a list of coordinates.
- Box Preview: A preview image that visualizes the detected and final cropping box.
Usage in ComfyUI Workflows
In a typical ComfyUI workflow, CropByMask V2
can be used as follows:
- Image Preprocessing: Before detailed analysis or further processing of an image, use this node to focus on specific areas by using a mask.
- Improving Performance: By reducing the image area to only regions of interest, subsequent image processing tasks can be more efficient, both in terms of speed and resource usage.
- Visualization Tasks: The node provides a preview of the cropping area, which is useful for verifying that the correct region of the image is being targeted.
Special Features and Considerations
- Customization: The node provides various options for detection modes and margin reserves, allowing a high degree of customization depending on the user’s needs.
- Handling of Multi-image Inputs: While primarily designed for single-image processing, the node can handle batches of images by treating them individually.
- Boundary Checks: Ensures that the cropping box does not exceed the dimensions of the original image, maintaining image integrity and avoiding errors.
- Compatibility with Other Nodes: The output images and masks can be seamlessly integrated into other nodes within a ComfyUI workflow, maintaining a smooth process pipeline.
By incorporating the LayerUtility: CropByMask V2
node into your ComfyUI workflows, you can enhance your image processing tasks with precise and efficient cropping based on customizable mask detection criteria.