Visit ComfyUI Online for ready-to-use ComfyUI environment
Powerful node for precise image cropping based on masks, ideal for AI artists and advanced detection methods.
LayerUtility: CropByMask V2 is a powerful node designed to crop images based on a specified mask. This node is particularly useful for AI artists who need to isolate specific regions of an image for further processing or analysis. By leveraging advanced detection methods, such as minimum bounding rectangle and maximum inscribed rectangle, this node ensures precise cropping around the masked area. Additionally, it offers flexibility with parameters like invert mask, reserve margins, and rounding to multiples, allowing you to fine-tune the cropping process to meet your specific needs. The main goal of this node is to provide a seamless and efficient way to crop images accurately, enhancing your workflow and enabling more focused image manipulation.
This parameter represents the input image that you want to crop. It should be provided in a tensor format, which is a common data structure used in image processing and machine learning.
The mask parameter is a binary or grayscale image that defines the area to be cropped. The non-zero regions of the mask indicate the parts of the image that should be retained after cropping.
This boolean parameter determines whether the mask should be inverted before processing. If set to True, the areas of the image corresponding to the zero regions of the mask will be retained, and vice versa. This is useful when you need to crop out the background or specific unwanted regions.
The detect parameter specifies the method used to determine the cropping area. It can take values like "min_bounding_rect" for the minimum bounding rectangle or "max_inscribed_rect" for the maximum inscribed rectangle. This allows you to choose the most suitable detection method for your specific use case.
This parameter defines the number of pixels to reserve at the top of the cropped area. It ensures that a margin is maintained above the detected region, which can be useful for preserving context or avoiding tight crops. The value should be a non-negative integer.
Similar to top_reserve, this parameter specifies the number of pixels to reserve at the bottom of the cropped area. It helps in maintaining a margin below the detected region. The value should be a non-negative integer.
This parameter sets the number of pixels to reserve on the left side of the cropped area. It ensures that a margin is maintained to the left of the detected region. The value should be a non-negative integer.
Similar to left_reserve, this parameter defines the number of pixels to reserve on the right side of the cropped area. It helps in maintaining a margin to the right of the detected region. The value should be a non-negative integer.
This parameter allows you to round the dimensions of the cropped area to the nearest multiple of a specified value. This is useful for ensuring that the cropped dimensions are compatible with certain processing requirements or constraints. The value should be a positive integer or 'None' if no rounding is needed.
The crop_box parameter is an optional input that allows you to specify a predefined cropping box. If provided, the node will use this box for cropping instead of calculating it based on the mask. The value should be a tuple of four integers representing the coordinates of the box (x1, y1, x2, y2).
This output parameter provides the cropped image based on the specified mask and other input parameters. The cropped image is returned in a tensor format, ready for further processing or analysis.
The cropped_mask parameter returns the mask corresponding to the cropped image. This is useful for maintaining the relationship between the image and its mask after cropping. The cropped mask is also provided in a tensor format.
This output parameter returns the coordinates of the cropping box used for the operation. It is a tuple of four integers (x1, y1, x2, y2) that represent the boundaries of the cropped area. This information can be useful for reference or further processing.
The preview_image parameter provides a visual representation of the cropping process. It includes the original image with the detected cropping box overlaid, allowing you to verify the accuracy of the cropping operation. The preview image is returned in a tensor format.
© Copyright 2024 RunComfy. All Rights Reserved.